| 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/memory/ptr_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/permissions/permissions_browsertest.h" | 10 #include "chrome/browser/permissions/permissions_browsertest.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 void TriggerPrompt() override { | 67 void TriggerPrompt() override { |
| 68 if (prompt_factory()->response_type() == | 68 if (prompt_factory()->response_type() == |
| 69 PermissionRequestManager::ACCEPT_ALL) { | 69 PermissionRequestManager::ACCEPT_ALL) { |
| 70 // If the prompt will be allowed, we need to wait for the page to refresh. | 70 // If the prompt will be allowed, we need to wait for the page to refresh. |
| 71 PageReloadWaiter reload_waiter(GetWebContents()); | 71 PageReloadWaiter reload_waiter(GetWebContents()); |
| 72 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); | 72 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); |
| 73 EXPECT_TRUE(reload_waiter.Wait()); | 73 EXPECT_TRUE(reload_waiter.Wait()); |
| 74 } else { | 74 } else { |
| 75 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); | 75 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); |
| 76 // Make a round trip to the renderer to flush any old did stop IPCs, |
| 77 // otherwise they can race with the next navigation and cause it to be |
| 78 // cancelled if it's the same URL. |
| 79 EXPECT_TRUE(ExecuteScript(GetWebContents(), std::string())); |
| 76 } | 80 } |
| 77 } | 81 } |
| 78 | 82 |
| 79 bool FeatureUsageSucceeds() override { | 83 bool FeatureUsageSucceeds() override { |
| 80 // If flash should have been blocked, reload the page to be sure that it is | 84 // If flash should have been blocked, reload the page to be sure that it is |
| 81 // blocked. | 85 // blocked. |
| 82 // | 86 // |
| 83 // NB: In cases where flash is allowed the page reloads automatically, | 87 // NB: In cases where flash is allowed the page reloads automatically, |
| 84 // and tests should always wait for that reload to finish before calling | 88 // and tests should always wait for that reload to finish before calling |
| 85 // this method. | 89 // this method. |
| 86 ui_test_utils::NavigateToURL(browser(), | 90 ui_test_utils::NavigateToURL(browser(), |
| 87 GetWebContents()->GetLastCommittedURL()); | 91 GetWebContents()->GetLastCommittedURL()); |
| 88 // If either flash with or without fallback content runs successfully it | 92 // If either flash with or without fallback content runs successfully it |
| 89 // indicates the feature is at least partly working, which could imply a | 93 // indicates the feature is at least partly working, which could imply a |
| 90 // faulty permission. | 94 // faulty permission. |
| 91 return RunScriptReturnBool("flashIsEnabled();") || | 95 return RunScriptReturnBool("flashIsEnabled();") || |
| 92 RunScriptReturnBool("flashIsEnabledForPluginWithoutFallback();"); | 96 RunScriptReturnBool("flashIsEnabledForPluginWithoutFallback();"); |
| 93 } | 97 } |
| 94 }; | 98 }; |
| 95 | 99 |
| 96 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, | 100 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, |
| 97 CommonFailsBeforeRequesting) { | 101 CommonFailsBeforeRequesting) { |
| 98 CommonFailsBeforeRequesting(); | 102 CommonFailsBeforeRequesting(); |
| 99 } | 103 } |
| 100 | 104 |
| 101 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfDismissed) { | 105 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfDismissed) { |
| 102 CommonFailsIfDismissed(); | 106 CommonFailsIfDismissed(); |
| 103 } | 107 } |
| 104 | 108 |
| 105 // https://crbug.com/706780 | 109 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonFailsIfBlocked) { |
| 106 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, | |
| 107 DISABLED_CommonFailsIfBlocked) { | |
| 108 CommonFailsIfBlocked(); | 110 CommonFailsIfBlocked(); |
| 109 } | 111 } |
| 110 | 112 |
| 111 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonSucceedsIfAllowed) { | 113 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, CommonSucceedsIfAllowed) { |
| 112 CommonSucceedsIfAllowed(); | 114 CommonSucceedsIfAllowed(); |
| 113 } | 115 } |
| 114 | 116 |
| 115 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, SucceedsInPopupWindow) { | 117 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, SucceedsInPopupWindow) { |
| 116 // Spawn the same page in a popup window and wait for it to finish loading. | 118 // Spawn the same page in a popup window and wait for it to finish loading. |
| 117 content::WebContents* original_contents = GetWebContents(); | 119 content::WebContents* original_contents = GetWebContents(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 CommonSucceedsIfAllowed(); | 201 CommonSucceedsIfAllowed(); |
| 200 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 202 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
| 201 | 203 |
| 202 // Navigate to a second URL to verify it's allowed on all file: URLs. | 204 // Navigate to a second URL to verify it's allowed on all file: URLs. |
| 203 ui_test_utils::NavigateToURL( | 205 ui_test_utils::NavigateToURL( |
| 204 browser(), | 206 browser(), |
| 205 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html")); | 207 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html")); |
| 206 EXPECT_TRUE(FeatureUsageSucceeds()); | 208 EXPECT_TRUE(FeatureUsageSucceeds()); |
| 207 } | 209 } |
| 208 | 210 |
| 209 // Failing often. http://crbug.com/706780. | 211 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, BlockFileURL) { |
| 210 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, DISABLED_BlockFileURL) { | |
| 211 base::FilePath test_path; | 212 base::FilePath test_path; |
| 212 PathService::Get(chrome::DIR_TEST_DATA, &test_path); | 213 PathService::Get(chrome::DIR_TEST_DATA, &test_path); |
| 213 ui_test_utils::NavigateToURL( | 214 ui_test_utils::NavigateToURL( |
| 214 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); | 215 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); |
| 215 CommonFailsIfBlocked(); | 216 CommonFailsIfBlocked(); |
| 216 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 217 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
| 217 | 218 |
| 218 // Navigate to a second URL to verify it's blocked on all file: URLs. | 219 // Navigate to a second URL to verify it's blocked on all file: URLs. |
| 219 ui_test_utils::NavigateToURL( | 220 ui_test_utils::NavigateToURL( |
| 220 browser(), | 221 browser(), |
| 221 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html")); | 222 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html")); |
| 222 EXPECT_FALSE(FeatureUsageSucceeds()); | 223 EXPECT_FALSE(FeatureUsageSucceeds()); |
| 223 } | 224 } |
| OLD | NEW |