OLD | NEW |
---|---|
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" | |
13 | 16 |
14 class FlashPermissionBrowserTest : public PermissionsBrowserTest { | 17 class FlashPermissionBrowserTest : public PermissionsBrowserTest { |
15 public: | 18 public: |
16 FlashPermissionBrowserTest() | 19 FlashPermissionBrowserTest() |
17 : PermissionsBrowserTest("/permissions/flash.html") {} | 20 : PermissionsBrowserTest("/permissions/flash.html") {} |
18 ~FlashPermissionBrowserTest() override {} | 21 ~FlashPermissionBrowserTest() override {} |
19 | 22 |
20 // PermissionsBrowserTest | 23 // PermissionsBrowserTest |
21 void SetUpCommandLine(base::CommandLine* command_line) override { | 24 void SetUpCommandLine(base::CommandLine* command_line) override { |
22 PermissionsBrowserTest::SetUpCommandLine(command_line); | 25 PermissionsBrowserTest::SetUpCommandLine(command_line); |
26 | |
23 ASSERT_TRUE(ppapi::RegisterFlashTestPlugin(command_line)); | 27 ASSERT_TRUE(ppapi::RegisterFlashTestPlugin(command_line)); |
24 | 28 |
25 feature_list_.InitAndEnableFeature(features::kPreferHtmlOverPlugins); | 29 // Set a high engagement threshhold so it doesn't interfere with testing the |
30 // permission. | |
31 command_line->AppendSwitchASCII( | |
32 switches::kEnableFeatures, "PreferHtmlOverPlugins<Study1"); | |
33 command_line->AppendSwitchASCII( | |
34 switches::kForceFieldTrials, "Study1/Enabled/"); | |
35 command_line->AppendSwitchASCII( | |
36 switches::kForceFieldTrialParams, | |
37 "Study1.Enabled:engagement_threshold_for_flash/100"); | |
26 } | 38 } |
27 | 39 |
28 void SetUpOnMainThread() override { | |
29 SiteEngagementScore::SetParamValuesForTesting(); | |
30 | |
31 PermissionsBrowserTest::SetUpOnMainThread(); | |
32 } | |
33 void TriggerPrompt() override { | 40 void TriggerPrompt() override { |
34 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); | 41 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); |
35 } | 42 } |
43 | |
36 bool FeatureUsageSucceeds() override { | 44 bool FeatureUsageSucceeds() override { |
37 // Flash won't be enabled until the page is refreshed. | 45 // Flash won't be enabled until the page is refreshed. |
38 ui_test_utils::NavigateToURL(browser(), | 46 ui_test_utils::NavigateToURL(browser(), |
39 GetWebContents()->GetLastCommittedURL()); | 47 GetWebContents()->GetLastCommittedURL()); |
40 return RunScriptReturnBool("flashIsEnabled();"); | 48 // If either flash with or without fallback content runs successfully it |
49 // indicates the feature is at least partly working, which could imply a | |
50 // faulty permission. | |
51 return RunScriptReturnBool("flashIsEnabled();") || | |
52 RunScriptReturnBool("flashIsEnabledForPluginWithoutFallack();"); | |
Bernhard Bauer
2016/10/04 09:21:00
Why not combine these expressions in Javascript?
raymes
2016/10/04 23:12:19
It's just a bit simpler to do it here, otherwise c
| |
41 } | 53 } |
42 | |
43 base::test::ScopedFeatureList feature_list_; | |
44 }; | 54 }; |
45 | 55 |
46 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, | 56 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, |
47 CommonFailsBeforeRequesting) { | 57 CommonFailsBeforeRequesting) { |
48 CommonFailsBeforeRequesting(); | 58 CommonFailsBeforeRequesting(); |
49 } | 59 } |
50 | 60 |
51 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfDismissed) { | 61 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfDismissed) { |
52 CommonFailsIfDismissed(); | 62 CommonFailsIfDismissed(); |
53 } | 63 } |
54 | 64 |
55 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfBlocked) { | 65 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfBlocked) { |
56 CommonFailsIfBlocked(); | 66 CommonFailsIfBlocked(); |
57 } | 67 } |
58 | 68 |
59 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonSucceedsIfAllowed) { | 69 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonSucceedsIfAllowed) { |
60 CommonSucceedsIfAllowed(); | 70 CommonSucceedsIfAllowed(); |
61 } | 71 } |
62 | 72 |
63 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) { | 73 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) { |
64 EXPECT_EQ(0, prompt_factory()->total_request_count()); | 74 EXPECT_EQ(0, prompt_factory()->total_request_count()); |
65 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); | 75 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
66 EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();")); | 76 EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();")); |
67 | 77 |
78 EXPECT_TRUE(FeatureUsageSucceeds()); | |
68 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 79 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
80 } | |
81 | |
82 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, | |
83 TriggerPromptViaPluginPlaceholder) { | |
84 EXPECT_EQ(0, prompt_factory()->total_request_count()); | |
85 EXPECT_FALSE(FeatureUsageSucceeds()); | |
86 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); | |
87 // We need to simulate a mouse click to trigger the placeholder to prompt. | |
88 content::SimulateMouseClickAt(GetWebContents(), 0 /* modifiers */, | |
89 blink::WebMouseEvent::Button::Left, | |
90 gfx::Point(50, 50)); | |
91 | |
69 EXPECT_TRUE(FeatureUsageSucceeds()); | 92 EXPECT_TRUE(FeatureUsageSucceeds()); |
93 EXPECT_EQ(1, prompt_factory()->total_request_count()); | |
70 } | 94 } |
OLD | NEW |