Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Side by Side Diff: chrome/browser/plugins/flash_permission_browsertest.cc

Issue 2385033002: Hookup the plugin placeholder to the Flash permission prompt (Closed)
Patch Set: Hookup the plugin placeholder to the Flash permission prompt Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/test/scoped_feature_list.h" 5 #include "base/base_switches.h"
6 #include "chrome/browser/engagement/site_engagement_score.h" 6 #include "base/command_line.h"
7 #include "chrome/browser/permissions/permissions_browsertest.h" 7 #include "chrome/browser/permissions/permissions_browsertest.h"
8 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h" 8 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h"
9 #include "chrome/common/chrome_features.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/test/base/ui_test_utils.h" 10 #include "chrome/test/base/ui_test_utils.h"
11 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
12 #include "content/public/common/content_switches.h"
13 #include "content/public/test/browser_test_utils.h"
12 #include "content/public/test/ppapi_test_utils.h" 14 #include "content/public/test/ppapi_test_utils.h"
15 #include "third_party/WebKit/public/web/WebInputEvent.h"
16 #include "url/gurl.h"
13 17
14 class FlashPermissionBrowserTest : public PermissionsBrowserTest { 18 class FlashPermissionBrowserTest : public PermissionsBrowserTest {
15 public: 19 public:
16 FlashPermissionBrowserTest() 20 FlashPermissionBrowserTest()
17 : PermissionsBrowserTest("/permissions/flash.html") {} 21 : PermissionsBrowserTest("/permissions/flash.html") {}
18 ~FlashPermissionBrowserTest() override {} 22 ~FlashPermissionBrowserTest() override {}
19 23
20 // PermissionsBrowserTest 24 // PermissionsBrowserTest
21 void SetUpCommandLine(base::CommandLine* command_line) override { 25 void SetUpCommandLine(base::CommandLine* command_line) override {
22 PermissionsBrowserTest::SetUpCommandLine(command_line); 26 PermissionsBrowserTest::SetUpCommandLine(command_line);
27
23 ASSERT_TRUE(ppapi::RegisterFlashTestPlugin(command_line)); 28 ASSERT_TRUE(ppapi::RegisterFlashTestPlugin(command_line));
24 29
25 feature_list_.InitAndEnableFeature(features::kPreferHtmlOverPlugins); 30 // Set a high engagement threshhold so it doesn't interfere with testing the
31 // permission.
32 command_line->AppendSwitchASCII(switches::kEnableFeatures,
33 "PreferHtmlOverPlugins<Study1");
34 command_line->AppendSwitchASCII(switches::kForceFieldTrials,
35 "Study1/Enabled/");
36 command_line->AppendSwitchASCII(
37 switches::kForceFieldTrialParams,
38 "Study1.Enabled:engagement_threshold_for_flash/100");
26 } 39 }
27 40
28 void SetUpOnMainThread() override { 41 void TriggerPrompt() override {
29 SiteEngagementScore::SetParamValuesForTesting(); 42 if (prompt_factory()->response_type() ==
43 PermissionRequestManager::ACCEPT_ALL) {
44 // If the prompt will be allowed, we need to wait for the page to refresh.
45 content::TestNavigationManager observer(GetWebContents(), GetTestUrl());
46 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();"));
47 observer.WaitForNavigationFinished();
48 } else {
49 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();"));
50 }
51 }
30 52
31 PermissionsBrowserTest::SetUpOnMainThread();
32 }
33 void TriggerPrompt() override {
34 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();"));
35 }
36 bool FeatureUsageSucceeds() override { 53 bool FeatureUsageSucceeds() override {
37 // Flash won't be enabled until the page is refreshed. 54 // Wait until the page is refreshed before testing whether flash is enabled
55 // or disabled.
38 ui_test_utils::NavigateToURL(browser(), 56 ui_test_utils::NavigateToURL(browser(),
39 GetWebContents()->GetLastCommittedURL()); 57 GetWebContents()->GetLastCommittedURL());
40 return RunScriptReturnBool("flashIsEnabled();"); 58 // If either flash with or without fallback content runs successfully it
59 // indicates the feature is at least partly working, which could imply a
60 // faulty permission.
61 return RunScriptReturnBool("flashIsEnabled();") ||
62 RunScriptReturnBool("flashIsEnabledForPluginWithoutFallback();");
41 } 63 }
42
43 base::test::ScopedFeatureList feature_list_;
44 }; 64 };
45 65
46 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, 66 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest,
47 CommonFailsBeforeRequesting) { 67 CommonFailsBeforeRequesting) {
48 CommonFailsBeforeRequesting(); 68 CommonFailsBeforeRequesting();
49 } 69 }
50 70
51 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfDismissed) { 71 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfDismissed) {
52 CommonFailsIfDismissed(); 72 CommonFailsIfDismissed();
53 } 73 }
54 74
55 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfBlocked) { 75 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfBlocked) {
56 CommonFailsIfBlocked(); 76 CommonFailsIfBlocked();
57 } 77 }
58 78
59 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonSucceedsIfAllowed) { 79 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonSucceedsIfAllowed) {
60 CommonSucceedsIfAllowed(); 80 CommonSucceedsIfAllowed();
61 } 81 }
62 82
63 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) { 83 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) {
64 EXPECT_EQ(0, prompt_factory()->total_request_count()); 84 EXPECT_EQ(0, prompt_factory()->total_request_count());
65 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); 85 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL);
66 EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();")); 86 EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();"));
67 87
88 EXPECT_TRUE(FeatureUsageSucceeds());
68 EXPECT_EQ(1, prompt_factory()->total_request_count()); 89 EXPECT_EQ(1, prompt_factory()->total_request_count());
90 }
91
92 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest,
93 TriggerPromptViaPluginPlaceholder) {
94 EXPECT_EQ(0, prompt_factory()->total_request_count());
95 EXPECT_FALSE(FeatureUsageSucceeds());
96 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL);
97 // We need to simulate a mouse click to trigger the placeholder to prompt.
98 content::TestNavigationManager observer(GetWebContents(), GetTestUrl());
99 content::SimulateMouseClickAt(GetWebContents(), 0 /* modifiers */,
100 blink::WebMouseEvent::Button::Left,
101 gfx::Point(50, 50));
102 observer.WaitForNavigationFinished();
103
69 EXPECT_TRUE(FeatureUsageSucceeds()); 104 EXPECT_TRUE(FeatureUsageSucceeds());
105 EXPECT_EQ(1, prompt_factory()->total_request_count());
70 } 106 }
OLDNEW
« no previous file with comments | « chrome/browser/plugins/flash_download_interception.cc ('k') | chrome/browser/plugins/plugin_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698