Chromium Code Reviews| 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 "base/path_service.h" |
| 8 #include "chrome/browser/permissions/permissions_browsertest.h" | 8 #include "chrome/browser/permissions/permissions_browsertest.h" |
| 9 #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" | 10 #include "chrome/common/chrome_paths.h" |
| 11 #include "chrome/test/base/ui_test_utils.h" | 11 #include "chrome/test/base/ui_test_utils.h" |
| 12 #include "components/variations/variations_switches.h" | 12 #include "components/variations/variations_switches.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
| 15 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
| 16 #include "content/public/test/ppapi_test_utils.h" | 16 #include "content/public/test/ppapi_test_utils.h" |
| 17 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 17 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 19 | 19 |
| 20 namespace { | |
| 21 | |
| 22 class PageReloadWaiter { | |
| 23 public: | |
| 24 explicit PageReloadWaiter(content::WebContents* web_contents) | |
| 25 : web_contents_(web_contents), | |
| 26 navigation_observer_(web_contents, | |
| 27 web_contents->GetLastCommittedURL()) {} | |
| 28 | |
| 29 bool Wait() { | |
| 30 navigation_observer_.WaitForNavigationFinished(); | |
| 31 return content::WaitForLoadStop(web_contents_); | |
| 32 } | |
| 33 | |
| 34 private: | |
| 35 content::WebContents* web_contents_; | |
| 36 content::TestNavigationManager navigation_observer_; | |
| 37 }; | |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 20 class FlashPermissionBrowserTest : public PermissionsBrowserTest { | 41 class FlashPermissionBrowserTest : public PermissionsBrowserTest { |
| 21 public: | 42 public: |
| 22 FlashPermissionBrowserTest() | 43 FlashPermissionBrowserTest() |
| 23 : PermissionsBrowserTest("/permissions/flash.html") {} | 44 : PermissionsBrowserTest("/permissions/flash.html") {} |
| 24 ~FlashPermissionBrowserTest() override {} | 45 ~FlashPermissionBrowserTest() override {} |
| 25 | 46 |
| 26 // PermissionsBrowserTest | 47 // PermissionsBrowserTest |
| 27 void SetUpCommandLine(base::CommandLine* command_line) override { | 48 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 28 PermissionsBrowserTest::SetUpCommandLine(command_line); | 49 PermissionsBrowserTest::SetUpCommandLine(command_line); |
| 29 | 50 |
| 30 ASSERT_TRUE(ppapi::RegisterFlashTestPlugin(command_line)); | 51 ASSERT_TRUE(ppapi::RegisterFlashTestPlugin(command_line)); |
| 31 | 52 |
| 32 // Set a high engagement threshhold so it doesn't interfere with testing the | 53 // Set a high engagement threshhold so it doesn't interfere with testing the |
| 33 // permission. | 54 // permission. |
| 34 command_line->AppendSwitchASCII(switches::kEnableFeatures, | 55 command_line->AppendSwitchASCII(switches::kEnableFeatures, |
| 35 "PreferHtmlOverPlugins<Study1"); | 56 "PreferHtmlOverPlugins<Study1"); |
| 36 command_line->AppendSwitchASCII(switches::kForceFieldTrials, | 57 command_line->AppendSwitchASCII(switches::kForceFieldTrials, |
| 37 "Study1/Enabled/"); | 58 "Study1/Enabled/"); |
| 38 command_line->AppendSwitchASCII( | 59 command_line->AppendSwitchASCII( |
| 39 variations::switches::kForceFieldTrialParams, | 60 variations::switches::kForceFieldTrialParams, |
| 40 "Study1.Enabled:engagement_threshold_for_flash/100"); | 61 "Study1.Enabled:engagement_threshold_for_flash/100"); |
| 41 } | 62 } |
| 42 | 63 |
| 43 void TriggerPrompt() override { | 64 void TriggerPrompt() override { |
| 44 if (prompt_factory()->response_type() == | 65 if (prompt_factory()->response_type() == |
| 45 PermissionRequestManager::ACCEPT_ALL) { | 66 PermissionRequestManager::ACCEPT_ALL) { |
| 46 // If the prompt will be allowed, we need to wait for the page to refresh. | 67 // If the prompt will be allowed, we need to wait for the page to refresh. |
| 47 content::TestNavigationManager observer( | 68 PageReloadWaiter reload_waiter(GetWebContents()); |
| 48 GetWebContents(), GetWebContents()->GetLastCommittedURL()); | |
| 49 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); | 69 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); |
| 50 observer.WaitForNavigationFinished(); | 70 EXPECT_TRUE(reload_waiter.Wait()); |
| 51 } else { | 71 } else { |
| 52 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); | 72 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); |
| 53 } | 73 } |
| 54 } | 74 } |
| 55 | 75 |
| 56 bool FeatureUsageSucceeds() override { | 76 bool FeatureUsageSucceeds() override { |
| 57 // Wait until the page is refreshed before testing whether flash is enabled | 77 // If flash should have been blocked, reload the page to be sure that it is |
| 58 // or disabled. | 78 // blocked. |
| 79 // NB: In cases where flash is allowed the page reloads automatically, | |
|
raymes
2016/12/06 00:02:53
nit: fill 80 chars above or add a newline between
Alexander Semashko
2016/12/06 00:14:14
Done.
| |
| 80 // and tests should always wait for this reload to finish before calling | |
|
raymes
2016/12/06 00:02:53
nit: this->that
Alexander Semashko
2016/12/06 00:14:14
Done.
| |
| 81 // this method. | |
| 59 ui_test_utils::NavigateToURL(browser(), | 82 ui_test_utils::NavigateToURL(browser(), |
| 60 GetWebContents()->GetLastCommittedURL()); | 83 GetWebContents()->GetLastCommittedURL()); |
| 61 // If either flash with or without fallback content runs successfully it | 84 // If either flash with or without fallback content runs successfully it |
| 62 // indicates the feature is at least partly working, which could imply a | 85 // indicates the feature is at least partly working, which could imply a |
| 63 // faulty permission. | 86 // faulty permission. |
| 64 return RunScriptReturnBool("flashIsEnabled();") || | 87 return RunScriptReturnBool("flashIsEnabled();") || |
| 65 RunScriptReturnBool("flashIsEnabledForPluginWithoutFallback();"); | 88 RunScriptReturnBool("flashIsEnabledForPluginWithoutFallback();"); |
| 66 } | 89 } |
| 67 }; | 90 }; |
| 68 | 91 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 79 CommonFailsIfBlocked(); | 102 CommonFailsIfBlocked(); |
| 80 } | 103 } |
| 81 | 104 |
| 82 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonSucceedsIfAllowed) { | 105 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonSucceedsIfAllowed) { |
| 83 CommonSucceedsIfAllowed(); | 106 CommonSucceedsIfAllowed(); |
| 84 } | 107 } |
| 85 | 108 |
| 86 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) { | 109 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) { |
| 87 EXPECT_EQ(0, prompt_factory()->total_request_count()); | 110 EXPECT_EQ(0, prompt_factory()->total_request_count()); |
| 88 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); | 111 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 112 // FlashPermissionContext::UpdateTabContext will reload the page, we'll have | |
| 113 // to wait until it is ready. | |
| 114 PageReloadWaiter reload_waiter(GetWebContents()); | |
| 89 EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();")); | 115 EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();")); |
| 116 EXPECT_TRUE(reload_waiter.Wait()); | |
| 90 | 117 |
| 91 EXPECT_TRUE(FeatureUsageSucceeds()); | 118 EXPECT_TRUE(FeatureUsageSucceeds()); |
| 92 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 119 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
| 93 } | 120 } |
| 94 | 121 |
| 95 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, | 122 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, |
| 96 TriggerPromptViaPluginPlaceholder) { | 123 TriggerPromptViaPluginPlaceholder) { |
| 97 EXPECT_EQ(0, prompt_factory()->total_request_count()); | 124 EXPECT_EQ(0, prompt_factory()->total_request_count()); |
| 98 EXPECT_FALSE(FeatureUsageSucceeds()); | 125 EXPECT_FALSE(FeatureUsageSucceeds()); |
| 99 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); | 126 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 100 // We need to simulate a mouse click to trigger the placeholder to prompt. | 127 // We need to simulate a mouse click to trigger the placeholder to prompt. |
| 101 content::TestNavigationManager observer( | 128 // When the prompt is auto-accepted, the page will be reloaded. |
| 102 GetWebContents(), GetWebContents()->GetLastCommittedURL()); | 129 PageReloadWaiter reload_waiter(GetWebContents()); |
| 103 content::SimulateMouseClickAt(GetWebContents(), 0 /* modifiers */, | 130 content::SimulateMouseClickAt(GetWebContents(), 0 /* modifiers */, |
| 104 blink::WebMouseEvent::Button::Left, | 131 blink::WebMouseEvent::Button::Left, |
| 105 gfx::Point(50, 50)); | 132 gfx::Point(50, 50)); |
| 106 observer.WaitForNavigationFinished(); | 133 EXPECT_TRUE(reload_waiter.Wait()); |
| 107 | 134 |
| 108 EXPECT_TRUE(FeatureUsageSucceeds()); | 135 EXPECT_TRUE(FeatureUsageSucceeds()); |
| 109 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 136 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
| 110 } | 137 } |
| 111 | 138 |
| 112 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, AllowFileURL) { | 139 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, AllowFileURL) { |
| 113 base::FilePath test_path; | 140 base::FilePath test_path; |
| 114 PathService::Get(chrome::DIR_TEST_DATA, &test_path); | 141 PathService::Get(chrome::DIR_TEST_DATA, &test_path); |
| 115 ui_test_utils::NavigateToURL( | 142 ui_test_utils::NavigateToURL( |
| 116 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); | 143 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 131 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); | 158 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); |
| 132 CommonFailsIfBlocked(); | 159 CommonFailsIfBlocked(); |
| 133 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 160 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
| 134 | 161 |
| 135 // Navigate to a second URL to verify it's blocked on all file: URLs. | 162 // Navigate to a second URL to verify it's blocked on all file: URLs. |
| 136 ui_test_utils::NavigateToURL( | 163 ui_test_utils::NavigateToURL( |
| 137 browser(), | 164 browser(), |
| 138 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html")); | 165 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html")); |
| 139 EXPECT_FALSE(FeatureUsageSucceeds()); | 166 EXPECT_FALSE(FeatureUsageSucceeds()); |
| 140 } | 167 } |
| OLD | NEW |