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/base_switches.h" | 5 #include "base/base_switches.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/path_service.h" |
7 #include "chrome/browser/permissions/permissions_browsertest.h" | 8 #include "chrome/browser/permissions/permissions_browsertest.h" |
8 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h" | 9 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h" |
| 10 #include "chrome/common/chrome_paths.h" |
9 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
11 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
12 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
13 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
14 #include "content/public/test/ppapi_test_utils.h" | 16 #include "content/public/test/ppapi_test_utils.h" |
15 #include "third_party/WebKit/public/web/WebInputEvent.h" | 17 #include "third_party/WebKit/public/web/WebInputEvent.h" |
16 #include "url/gurl.h" | 18 #include "url/gurl.h" |
17 | 19 |
18 class FlashPermissionBrowserTest : public PermissionsBrowserTest { | 20 class FlashPermissionBrowserTest : public PermissionsBrowserTest { |
(...skipping 16 matching lines...) Expand all Loading... |
35 "Study1/Enabled/"); | 37 "Study1/Enabled/"); |
36 command_line->AppendSwitchASCII( | 38 command_line->AppendSwitchASCII( |
37 switches::kForceFieldTrialParams, | 39 switches::kForceFieldTrialParams, |
38 "Study1.Enabled:engagement_threshold_for_flash/100"); | 40 "Study1.Enabled:engagement_threshold_for_flash/100"); |
39 } | 41 } |
40 | 42 |
41 void TriggerPrompt() override { | 43 void TriggerPrompt() override { |
42 if (prompt_factory()->response_type() == | 44 if (prompt_factory()->response_type() == |
43 PermissionRequestManager::ACCEPT_ALL) { | 45 PermissionRequestManager::ACCEPT_ALL) { |
44 // If the prompt will be allowed, we need to wait for the page to refresh. | 46 // If the prompt will be allowed, we need to wait for the page to refresh. |
45 content::TestNavigationManager observer(GetWebContents(), GetTestUrl()); | 47 content::TestNavigationManager observer( |
| 48 GetWebContents(), GetWebContents()->GetLastCommittedURL()); |
46 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); | 49 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); |
47 observer.WaitForNavigationFinished(); | 50 observer.WaitForNavigationFinished(); |
48 } else { | 51 } else { |
49 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); | 52 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); |
50 } | 53 } |
51 } | 54 } |
52 | 55 |
53 bool FeatureUsageSucceeds() override { | 56 bool FeatureUsageSucceeds() override { |
54 // Wait until the page is refreshed before testing whether flash is enabled | 57 // Wait until the page is refreshed before testing whether flash is enabled |
55 // or disabled. | 58 // or disabled. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 EXPECT_TRUE(FeatureUsageSucceeds()); | 91 EXPECT_TRUE(FeatureUsageSucceeds()); |
89 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 92 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
90 } | 93 } |
91 | 94 |
92 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, | 95 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, |
93 TriggerPromptViaPluginPlaceholder) { | 96 TriggerPromptViaPluginPlaceholder) { |
94 EXPECT_EQ(0, prompt_factory()->total_request_count()); | 97 EXPECT_EQ(0, prompt_factory()->total_request_count()); |
95 EXPECT_FALSE(FeatureUsageSucceeds()); | 98 EXPECT_FALSE(FeatureUsageSucceeds()); |
96 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); | 99 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
97 // We need to simulate a mouse click to trigger the placeholder to prompt. | 100 // We need to simulate a mouse click to trigger the placeholder to prompt. |
98 content::TestNavigationManager observer(GetWebContents(), GetTestUrl()); | 101 content::TestNavigationManager observer( |
| 102 GetWebContents(), GetWebContents()->GetLastCommittedURL()); |
99 content::SimulateMouseClickAt(GetWebContents(), 0 /* modifiers */, | 103 content::SimulateMouseClickAt(GetWebContents(), 0 /* modifiers */, |
100 blink::WebMouseEvent::Button::Left, | 104 blink::WebMouseEvent::Button::Left, |
101 gfx::Point(50, 50)); | 105 gfx::Point(50, 50)); |
102 observer.WaitForNavigationFinished(); | 106 observer.WaitForNavigationFinished(); |
103 | 107 |
104 EXPECT_TRUE(FeatureUsageSucceeds()); | 108 EXPECT_TRUE(FeatureUsageSucceeds()); |
105 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 109 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
106 } | 110 } |
| 111 |
| 112 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, AllowFileURL) { |
| 113 base::FilePath test_path; |
| 114 PathService::Get(chrome::DIR_TEST_DATA, &test_path); |
| 115 ui_test_utils::NavigateToURL( |
| 116 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); |
| 117 CommonSucceedsIfAllowed(); |
| 118 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
| 119 |
| 120 // Navigate to a second URL to verify it's allowed on all file: URLs. |
| 121 ui_test_utils::NavigateToURL( |
| 122 browser(), |
| 123 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html")); |
| 124 EXPECT_TRUE(FeatureUsageSucceeds()); |
| 125 } |
| 126 |
| 127 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, BlockFileURL) { |
| 128 base::FilePath test_path; |
| 129 PathService::Get(chrome::DIR_TEST_DATA, &test_path); |
| 130 ui_test_utils::NavigateToURL( |
| 131 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); |
| 132 CommonFailsIfBlocked(); |
| 133 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
| 134 |
| 135 // Navigate to a second URL to verify it's blocked on all file: URLs. |
| 136 ui_test_utils::NavigateToURL( |
| 137 browser(), |
| 138 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html")); |
| 139 EXPECT_FALSE(FeatureUsageSucceeds()); |
| 140 } |
OLD | NEW |