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 <map> | 7 #include <map> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
24 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
27 | 27 |
28 #if !defined(OS_ANDROID) | 28 #if !defined(OS_ANDROID) |
29 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 30 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 31 #include "chrome/common/pref_names.h" |
31 #include "chrome/test/base/browser_with_test_window_test.h" | 32 #include "chrome/test/base/browser_with_test_window_test.h" |
32 #include "chrome/test/base/search_test_utils.h" | 33 #include "chrome/test/base/search_test_utils.h" |
33 #endif | 34 #endif |
34 | 35 |
35 using ChromeContentBrowserClientTest = testing::Test; | 36 using ChromeContentBrowserClientTest = testing::Test; |
36 | 37 |
37 TEST_F(ChromeContentBrowserClientTest, ShouldAssignSiteForURL) { | 38 TEST_F(ChromeContentBrowserClientTest, ShouldAssignSiteForURL) { |
38 ChromeContentBrowserClient client; | 39 ChromeContentBrowserClient client; |
39 EXPECT_FALSE(client.ShouldAssignSiteForURL(GURL("chrome-native://test"))); | 40 EXPECT_FALSE(client.ShouldAssignSiteForURL(GURL("chrome-native://test"))); |
40 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("http://www.google.com"))); | 41 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("http://www.google.com"))); |
41 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("https://www.google.com"))); | 42 EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("https://www.google.com"))); |
42 } | 43 } |
43 | 44 |
44 // BrowserWithTestWindowTest doesn't work on Android. | 45 // BrowserWithTestWindowTest doesn't work on Android. |
45 #if !defined(OS_ANDROID) | 46 #if !defined(OS_ANDROID) |
46 | 47 |
47 using ChromeContentBrowserClientWindowTest = BrowserWithTestWindowTest; | 48 using ChromeContentBrowserClientWindowTest = BrowserWithTestWindowTest; |
48 | 49 |
49 static void DidOpenURLForWindowTest(content::WebContents** target_contents, | 50 static void DidOpenURLForWindowTest(content::WebContents** target_contents, |
50 content::WebContents* opened_contents) { | 51 content::WebContents* opened_contents) { |
51 DCHECK(target_contents); | 52 DCHECK(target_contents); |
52 | 53 |
53 *target_contents = opened_contents; | 54 *target_contents = opened_contents; |
54 } | 55 } |
55 | 56 |
| 57 TEST_F(ChromeContentBrowserClientWindowTest, IsDataSaverEnabled) { |
| 58 ChromeContentBrowserClient client; |
| 59 content::BrowserContext* context = browser()->profile(); |
| 60 EXPECT_FALSE(client.IsDataSaverEnabled(context)); |
| 61 browser()->profile()->GetPrefs()->SetBoolean(prefs::kDataSaverEnabled, true); |
| 62 EXPECT_TRUE(client.IsDataSaverEnabled(context)); |
| 63 } |
| 64 |
56 // This test opens two URLs using ContentBrowserClient::OpenURL. It expects the | 65 // This test opens two URLs using ContentBrowserClient::OpenURL. It expects the |
57 // URLs to be opened in new tabs and activated, changing the active tabs after | 66 // URLs to be opened in new tabs and activated, changing the active tabs after |
58 // each call and increasing the tab count by 2. | 67 // each call and increasing the tab count by 2. |
59 TEST_F(ChromeContentBrowserClientWindowTest, OpenURL) { | 68 TEST_F(ChromeContentBrowserClientWindowTest, OpenURL) { |
60 ChromeContentBrowserClient client; | 69 ChromeContentBrowserClient client; |
61 | 70 |
62 int previous_count = browser()->tab_strip_model()->count(); | 71 int previous_count = browser()->tab_strip_model()->count(); |
63 | 72 |
64 GURL urls[] = { GURL("https://www.google.com"), | 73 GURL urls[] = { GURL("https://www.google.com"), |
65 GURL("https://www.chromium.org") }; | 74 GURL("https://www.chromium.org") }; |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 377 |
369 NavigationEntry* entry = browser()->tab_strip_model()-> | 378 NavigationEntry* entry = browser()->tab_strip_model()-> |
370 GetActiveWebContents()->GetController().GetLastCommittedEntry(); | 379 GetActiveWebContents()->GetController().GetLastCommittedEntry(); |
371 ASSERT_TRUE(entry != NULL); | 380 ASSERT_TRUE(entry != NULL); |
372 EXPECT_EQ(url_rewritten, entry->GetURL()); | 381 EXPECT_EQ(url_rewritten, entry->GetURL()); |
373 EXPECT_EQ(url_original, entry->GetVirtualURL()); | 382 EXPECT_EQ(url_original, entry->GetVirtualURL()); |
374 } | 383 } |
375 | 384 |
376 } // namespace content | 385 } // namespace content |
377 #endif // !defined(OS_ANDROID) | 386 #endif // !defined(OS_ANDROID) |
OLD | NEW |