| 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 "chrome/browser/permissions/permissions_browsertest.h" | 5 #include "chrome/browser/permissions/permissions_browsertest.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/permissions/permission_request_manager.h" | 8 #include "chrome/browser/permissions/permission_request_manager.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 void PermissionsBrowserTest::SetUpOnMainThread() { | 23 void PermissionsBrowserTest::SetUpOnMainThread() { |
| 24 InProcessBrowserTest::SetUpOnMainThread(); | 24 InProcessBrowserTest::SetUpOnMainThread(); |
| 25 | 25 |
| 26 PermissionRequestManager* manager = PermissionRequestManager::FromWebContents( | 26 PermissionRequestManager* manager = PermissionRequestManager::FromWebContents( |
| 27 browser()->tab_strip_model()->GetActiveWebContents()); | 27 browser()->tab_strip_model()->GetActiveWebContents()); |
| 28 prompt_factory_.reset(new MockPermissionPromptFactory(manager)); | 28 prompt_factory_.reset(new MockPermissionPromptFactory(manager)); |
| 29 manager->DisplayPendingRequests(); | 29 manager->DisplayPendingRequests(); |
| 30 | 30 |
| 31 ASSERT_TRUE(embedded_test_server()->Start()); | 31 ASSERT_TRUE(embedded_test_server()->Start()); |
| 32 | 32 |
| 33 ui_test_utils::NavigateToURL(browser(), GetTestUrl()); | 33 ui_test_utils::NavigateToURL(browser(), |
| 34 embedded_test_server()->GetURL(test_url())); |
| 34 } | 35 } |
| 35 | 36 |
| 36 void PermissionsBrowserTest::TearDownOnMainThread() { | 37 void PermissionsBrowserTest::TearDownOnMainThread() { |
| 37 prompt_factory_.reset(); | 38 prompt_factory_.reset(); |
| 38 | 39 |
| 39 InProcessBrowserTest::TearDownOnMainThread(); | 40 InProcessBrowserTest::TearDownOnMainThread(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 bool PermissionsBrowserTest::RunScriptReturnBool(const std::string& script) { | 43 bool PermissionsBrowserTest::RunScriptReturnBool(const std::string& script) { |
| 43 bool result; | 44 bool result; |
| 44 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 45 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 45 GetWebContents()->GetMainFrame(), script, &result)); | 46 GetWebContents()->GetMainFrame(), script, &result)); |
| 46 return result; | 47 return result; |
| 47 } | 48 } |
| 48 | 49 |
| 49 content::WebContents* PermissionsBrowserTest::GetWebContents() { | 50 content::WebContents* PermissionsBrowserTest::GetWebContents() { |
| 50 return browser()->tab_strip_model()->GetActiveWebContents(); | 51 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 51 } | 52 } |
| 52 | 53 |
| 53 GURL PermissionsBrowserTest::GetTestUrl() { | |
| 54 return embedded_test_server()->GetURL(test_url()); | |
| 55 } | |
| 56 | |
| 57 void PermissionsBrowserTest::CommonFailsBeforeRequesting() { | 54 void PermissionsBrowserTest::CommonFailsBeforeRequesting() { |
| 58 EXPECT_EQ(0, prompt_factory()->total_request_count()); | 55 EXPECT_EQ(0, prompt_factory()->total_request_count()); |
| 59 // Dismiss any prompts if they are shown when using the feature. | 56 // Dismiss any prompts if they are shown when using the feature. |
| 60 prompt_factory()->set_response_type(PermissionRequestManager::DISMISS); | 57 prompt_factory()->set_response_type(PermissionRequestManager::DISMISS); |
| 61 EXPECT_FALSE(FeatureUsageSucceeds()); | 58 EXPECT_FALSE(FeatureUsageSucceeds()); |
| 62 } | 59 } |
| 63 | 60 |
| 64 void PermissionsBrowserTest::CommonFailsIfDismissed() { | 61 void PermissionsBrowserTest::CommonFailsIfDismissed() { |
| 65 EXPECT_EQ(0, prompt_factory()->total_request_count()); | 62 EXPECT_EQ(0, prompt_factory()->total_request_count()); |
| 66 prompt_factory()->set_response_type(PermissionRequestManager::DISMISS); | 63 prompt_factory()->set_response_type(PermissionRequestManager::DISMISS); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 80 } | 77 } |
| 81 | 78 |
| 82 void PermissionsBrowserTest::CommonSucceedsIfAllowed() { | 79 void PermissionsBrowserTest::CommonSucceedsIfAllowed() { |
| 83 EXPECT_EQ(0, prompt_factory()->total_request_count()); | 80 EXPECT_EQ(0, prompt_factory()->total_request_count()); |
| 84 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); | 81 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 85 TriggerPrompt(); | 82 TriggerPrompt(); |
| 86 | 83 |
| 87 EXPECT_TRUE(FeatureUsageSucceeds()); | 84 EXPECT_TRUE(FeatureUsageSucceeds()); |
| 88 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 85 EXPECT_EQ(1, prompt_factory()->total_request_count()); |
| 89 } | 86 } |
| OLD | NEW |