Skip to content

Commit

Permalink
Issue 1549: Return constant results for navigator.plugins and navigat…
Browse files Browse the repository at this point in the history
…or.mimeTypes

auditors: @diracdeltas
  • Loading branch information
jumde committed Nov 1, 2018
1 parent 332a98c commit 1e390a8
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "base/path_service.h"
#include "brave/browser/brave_content_browser_client.h"
#include "brave/common/brave_paths.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_content_client.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/browser_test_utils.h"

const char kNavigatorPluginsTest[] = "/navigatorplugins.html";
const char kNavigatorMimeTypesTest[] = "/navigatormimetypes.html";

class NavigatorPluginsTest : public InProcessBrowserTest {
public:
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();

content_client_.reset(new ChromeContentClient);
content::SetContentClient(content_client_.get());
browser_content_client_.reset(new BraveContentBrowserClient());
content::SetBrowserClientForTesting(browser_content_client_.get());
content::SetupCrossSiteRedirector(embedded_test_server());

brave::RegisterPathProvider();
base::FilePath test_data_dir;
base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir);
embedded_test_server()->ServeFilesFromDirectory(test_data_dir);

ASSERT_TRUE(embedded_test_server()->Start());
}

void TearDown() override {
browser_content_client_.reset();
content_client_.reset();
}

private:
std::unique_ptr<ChromeContentClient> content_client_;
std::unique_ptr<BraveContentBrowserClient> browser_content_client_;
base::ScopedTempDir temp_user_data_dir_;
};

IN_PROC_BROWSER_TEST_F(NavigatorPluginsTest, ConstPlugins) {
GURL url = embedded_test_server()->GetURL(kNavigatorPluginsTest);
ui_test_utils::NavigateToURL(browser(), url);
content::WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(content::WaitForLoadStop(contents));
EXPECT_EQ(url, contents->GetURL());

bool constantPlugins;
ASSERT_TRUE(ExecuteScriptAndExtractBool(
contents,
"window.domAutomationController.send(constantPlugins())",
&constantPlugins));
EXPECT_TRUE(constantPlugins);
}

IN_PROC_BROWSER_TEST_F(NavigatorPluginsTest, ConstMimeTypes) {
GURL url = embedded_test_server()->GetURL(kNavigatorMimeTypesTest);
ui_test_utils::NavigateToURL(browser(), url);
content::WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(content::WaitForLoadStop(contents));
EXPECT_EQ(url, contents->GetURL());

bool constantMimeTypes;
ASSERT_TRUE(ExecuteScriptAndExtractBool(
contents,
"window.domAutomationController.send(constantMimeTypes())",
&constantMimeTypes));
EXPECT_TRUE(constantMimeTypes);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/third_party/blink/renderer/platform/plugins/plugin_data.cc b/third_party/blink/renderer/platform/plugins/plugin_data.cc
index 02d54d5f2dbf37a5de6ccaee3a825416b911b42c..6b1789b4fb65ad31a45bb764400f4aa040282857 100644
--- a/third_party/blink/renderer/platform/plugins/plugin_data.cc
+++ b/third_party/blink/renderer/platform/plugins/plugin_data.cc
@@ -108,6 +108,9 @@ void PluginData::UpdatePluginList(const SecurityOrigin* main_frame_origin) {
Vector<mojom::blink::PluginInfoPtr> plugins;
registry->GetPlugins(false, legacy_origin, &plugins);
for (const auto& plugin : plugins) {
+ if (plugin->name != "Shockwave Flash") {
+ return;
+ }
auto* plugin_info =
new PluginInfo(plugin->name, FilePathToWebString(plugin->filename),
plugin->description, plugin->background_color);
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ test("brave_browser_tests") {
"//brave/chromium_src/third_party/blink/renderer/modules/battery/navigator_batterytest.cc",
"//brave/chromium_src/third_party/blink/renderer/modules/bluetooth/navigator_bluetoothtest.cc",
"//brave/chromium_src/third_party/blink/renderer/modules/credentialmanager/credentials_containertest.cc",
"//brave/chromium_src/third_party/blink/renderer/modules/plugins/navigator_pluginstest.cc",
"//brave/browser/autoplay/autoplay_permission_context_browsertest.cc",
"//brave/browser/brave_content_browser_client_browsertest.cc",
"//brave/browser/brave_features_browsertest.cc",
Expand Down
5 changes: 5 additions & 0 deletions test/data/navigatormimetypes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
function constantMimeTypes() {
return navigator.mimeTypes.length == 0;
}
</script>
5 changes: 5 additions & 0 deletions test/data/navigatorplugins.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
function constantPlugins() {
return navigator.plugins.length == 0;
}
</script>

0 comments on commit 1e390a8

Please sign in to comment.