| 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/memory/ptr_util.h" |
| 7 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 8 #include "chrome/browser/permissions/permissions_browsertest.h" | 9 #include "chrome/browser/permissions/permissions_browsertest.h" |
| 9 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h" | 10 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h" |
| 10 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
| 11 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
| 12 #include "components/variations/variations_switches.h" | 13 #include "components/variations/variations_switches.h" |
| 13 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 15 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
| 16 #include "content/public/test/ppapi_test_utils.h" | 17 #include "content/public/test/ppapi_test_utils.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 77 } |
| 77 | 78 |
| 78 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfBlocked) { | 79 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfBlocked) { |
| 79 CommonFailsIfBlocked(); | 80 CommonFailsIfBlocked(); |
| 80 } | 81 } |
| 81 | 82 |
| 82 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonSucceedsIfAllowed) { | 83 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonSucceedsIfAllowed) { |
| 83 CommonSucceedsIfAllowed(); | 84 CommonSucceedsIfAllowed(); |
| 84 } | 85 } |
| 85 | 86 |
| 87 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, SucceedsInPopupWindow) { |
| 88 // Spawn the same page in a popup window and wait for it to finish loading. |
| 89 content::WebContents* original_contents = GetWebContents(); |
| 90 ASSERT_TRUE(RunScriptReturnBool("spawnPopupAndAwaitLoad();")); |
| 91 |
| 92 // Assert that the popup's WebContents is now the active one. |
| 93 ASSERT_NE(original_contents, GetWebContents()); |
| 94 |
| 95 PermissionRequestManager* manager = PermissionRequestManager::FromWebContents( |
| 96 GetWebContents()); |
| 97 auto popup_prompt_factory = |
| 98 base::MakeUnique<MockPermissionPromptFactory>(manager); |
| 99 manager->DisplayPendingRequests(); |
| 100 |
| 101 EXPECT_EQ(0, popup_prompt_factory->total_request_count()); |
| 102 popup_prompt_factory->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 103 // FlashPermissionContext::UpdateTabContext will reload the page, we'll have |
| 104 // to wait until it is ready. |
| 105 PageReloadWaiter reload_waiter(GetWebContents()); |
| 106 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); |
| 107 EXPECT_TRUE(reload_waiter.Wait()); |
| 108 |
| 109 EXPECT_TRUE(FeatureUsageSucceeds()); |
| 110 EXPECT_EQ(1, popup_prompt_factory->total_request_count()); |
| 111 |
| 112 // Shut down the popup window tab, as the normal test teardown assumes there |
| 113 // is only one test tab. |
| 114 popup_prompt_factory.reset(); |
| 115 GetWebContents()->Close(); |
| 116 } |
| 117 |
| 86 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) { | 118 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) { |
| 87 EXPECT_EQ(0, prompt_factory()->total_request_count()); | 119 EXPECT_EQ(0, prompt_factory()->total_request_count()); |
| 88 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); | 120 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 89 EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();")); | 121 EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();")); |
| 90 | 122 |
| 91 EXPECT_TRUE(FeatureUsageSucceeds()); | 123 EXPECT_TRUE(FeatureUsageSucceeds()); |
| 92 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 124 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
| 93 } | 125 } |
| 94 | 126 |
| 95 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, | 127 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); | 163 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); |
| 132 CommonFailsIfBlocked(); | 164 CommonFailsIfBlocked(); |
| 133 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 165 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
| 134 | 166 |
| 135 // Navigate to a second URL to verify it's blocked on all file: URLs. | 167 // Navigate to a second URL to verify it's blocked on all file: URLs. |
| 136 ui_test_utils::NavigateToURL( | 168 ui_test_utils::NavigateToURL( |
| 137 browser(), | 169 browser(), |
| 138 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html")); | 170 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html")); |
| 139 EXPECT_FALSE(FeatureUsageSucceeds()); | 171 EXPECT_FALSE(FeatureUsageSucceeds()); |
| 140 } | 172 } |
| OLD | NEW |