| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chrome_content_browser_client.h" | 5 #include "chrome/browser/chrome_content_browser_client.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "chrome/browser/search_engines/template_url_service_factory.h" | 9 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/test/base/browser_with_test_window_test.h" | 12 #include "chrome/test/base/browser_with_test_window_test.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "components/search_engines/template_url_service.h" | 14 #include "components/search_engines/template_url_service.h" |
| 15 #include "components/variations/entropy_provider.h" | 15 #include "components/variations/entropy_provider.h" |
| 16 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
| 17 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 22 | 22 |
| 23 namespace chrome { | 23 namespace chrome { |
| 24 | 24 |
| 25 typedef testing::Test ChromeContentBrowserClientTest; | 25 using ChromeContentBrowserClientTest = testing::Test; |
| 26 | 26 |
| 27 TEST_F(ChromeContentBrowserClientTest, ShouldAssignSiteForURL) { | 27 TEST_F(ChromeContentBrowserClientTest, ShouldAssignSiteForURL) { |
| 28 ChromeContentBrowserClient client; | 28 ChromeContentBrowserClient client; |
| 29 EXPECT_FALSE(client.ShouldAssignSiteForURL(GURL("chrome-native://test"))); | 29 EXPECT_FALSE(client.ShouldAssignSiteForURL(GURL("chrome-native://test"))); |
| 30 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("http://www.google.com"))); | 30 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("http://www.google.com"))); |
| 31 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("https://www.google.com"))); | 31 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("https://www.google.com"))); |
| 32 } | 32 } |
| 33 | 33 |
| 34 using ChromeContentBrowserClientWindowTest = BrowserWithTestWindowTest; |
| 35 |
| 36 // BrowserWithTestWindowTest doesn't work on iOS and Android. |
| 37 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 38 |
| 39 // This test opens two URLs using ContentBrowserClient::OpenURL. It expects the |
| 40 // URLs to be opened in new tabs and activated, changing the active tabs after |
| 41 // each call and increasing the tab count by 2. |
| 42 TEST_F(ChromeContentBrowserClientWindowTest, OpenURL) { |
| 43 ChromeContentBrowserClient client; |
| 44 |
| 45 int previous_count = browser()->tab_strip_model()->count(); |
| 46 |
| 47 GURL urls[] = { GURL("https://www.google.com"), |
| 48 GURL("https://www.chromium.org") }; |
| 49 |
| 50 for (const GURL& url : urls) { |
| 51 content::OpenURLParams params(url, |
| 52 content::Referrer(), |
| 53 NEW_FOREGROUND_TAB, |
| 54 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 55 false); |
| 56 content::WebContents* contents = |
| 57 client.OpenURL(browser()->profile(), params); |
| 58 EXPECT_TRUE(contents); |
| 59 |
| 60 content::WebContents* active_contents = browser()->tab_strip_model()-> |
| 61 GetActiveWebContents(); |
| 62 EXPECT_EQ(contents, active_contents); |
| 63 EXPECT_EQ(url, active_contents->GetVisibleURL()); |
| 64 } |
| 65 |
| 66 EXPECT_EQ(previous_count + 2, browser()->tab_strip_model()->count()); |
| 67 } |
| 68 |
| 69 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
| 70 |
| 34 // NOTE: Any updates to the expectations in these tests should also be done in | 71 // NOTE: Any updates to the expectations in these tests should also be done in |
| 35 // the browser test WebRtcDisableEncryptionFlagBrowserTest. | 72 // the browser test WebRtcDisableEncryptionFlagBrowserTest. |
| 36 class DisableWebRtcEncryptionFlagTest : public testing::Test { | 73 class DisableWebRtcEncryptionFlagTest : public testing::Test { |
| 37 public: | 74 public: |
| 38 DisableWebRtcEncryptionFlagTest() | 75 DisableWebRtcEncryptionFlagTest() |
| 39 : from_command_line_(base::CommandLine::NO_PROGRAM), | 76 : from_command_line_(base::CommandLine::NO_PROGRAM), |
| 40 to_command_line_(base::CommandLine::NO_PROGRAM) {} | 77 to_command_line_(base::CommandLine::NO_PROGRAM) {} |
| 41 | 78 |
| 42 protected: | 79 protected: |
| 43 void SetUp() override { | 80 void SetUp() override { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 167 |
| 131 NavigationEntry* entry = browser()->tab_strip_model()-> | 168 NavigationEntry* entry = browser()->tab_strip_model()-> |
| 132 GetActiveWebContents()->GetController().GetLastCommittedEntry(); | 169 GetActiveWebContents()->GetController().GetLastCommittedEntry(); |
| 133 ASSERT_TRUE(entry != NULL); | 170 ASSERT_TRUE(entry != NULL); |
| 134 EXPECT_EQ(url_rewritten, entry->GetURL()); | 171 EXPECT_EQ(url_rewritten, entry->GetURL()); |
| 135 EXPECT_EQ(url_original, entry->GetVirtualURL()); | 172 EXPECT_EQ(url_original, entry->GetVirtualURL()); |
| 136 } | 173 } |
| 137 | 174 |
| 138 } // namespace content | 175 } // namespace content |
| 139 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) | 176 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) |
| OLD | NEW |