[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/chrome_content_browser_client.h" |
| 6 | |
[email protected] | 10a9bf9 | 2013-11-13 23:34:48 | [diff] [blame^] | 7 | #include "base/metrics/field_trial.h" |
| 8 | #include "chrome/browser/search_engines/template_url_service.h" |
| 9 | #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 10 | #include "chrome/browser/ui/browser.h" |
| 11 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 | #include "chrome/test/base/browser_with_test_window_test.h" |
| 13 | #include "chrome/test/base/ui_test_utils.h" |
| 14 | #include "components/variations/entropy_provider.h" |
| 15 | #include "content/public/browser/navigation_controller.h" |
| 16 | #include "content/public/browser/navigation_entry.h" |
| 17 | #include "content/public/browser/web_contents.h" |
[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 18 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 5f5ef80 | 2013-07-04 16:11:13 | [diff] [blame] | 19 | #include "url/gurl.h" |
[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 20 | |
| 21 | namespace chrome { |
| 22 | |
| 23 | typedef testing::Test ChromeContentBrowserClientTest; |
| 24 | |
| 25 | |
| 26 | TEST_F(ChromeContentBrowserClientTest, ShouldAssignSiteForURL) { |
| 27 | ChromeContentBrowserClient client; |
| 28 | EXPECT_FALSE(client.ShouldAssignSiteForURL(GURL("chrome-native://test"))); |
| 29 | EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("http://www.google.com"))); |
| 30 | EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("https://www.google.com"))); |
| 31 | } |
| 32 | |
| 33 | } // namespace chrome |
[email protected] | 10a9bf9 | 2013-11-13 23:34:48 | [diff] [blame^] | 34 | |
| 35 | #if !defined(OS_IOS) && !defined(OS_ANDROID) |
| 36 | namespace content { |
| 37 | |
| 38 | class InstantNTPURLRewriteTest : public BrowserWithTestWindowTest { |
| 39 | protected: |
| 40 | virtual void SetUp() OVERRIDE { |
| 41 | BrowserWithTestWindowTest::SetUp(); |
| 42 | field_trial_list_.reset(new base::FieldTrialList( |
| 43 | new metrics::SHA1EntropyProvider("42"))); |
| 44 | } |
| 45 | |
| 46 | void InstallTemplateURLWithNewTabPage(GURL new_tab_page_url) { |
| 47 | TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 48 | profile(), &TemplateURLServiceFactory::BuildInstanceFor); |
| 49 | TemplateURLService* template_url_service = |
| 50 | TemplateURLServiceFactory::GetForProfile(browser()->profile()); |
| 51 | ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); |
| 52 | |
| 53 | TemplateURLData data; |
| 54 | data.SetURL("http://foo.com/url?bar={searchTerms}"); |
| 55 | data.new_tab_url = new_tab_page_url.spec(); |
| 56 | TemplateURL* template_url = new TemplateURL(browser()->profile(), data); |
| 57 | // Takes ownership. |
| 58 | template_url_service->Add(template_url); |
| 59 | template_url_service->SetDefaultSearchProvider(template_url); |
| 60 | } |
| 61 | |
| 62 | scoped_ptr<base::FieldTrialList> field_trial_list_; |
| 63 | }; |
| 64 | |
| 65 | TEST_F(InstantNTPURLRewriteTest, UberURLHandler_InstantExtendedNewTabPage) { |
| 66 | const GURL url_original("chrome://newtab"); |
| 67 | const GURL url_rewritten("https://www.example.com/newtab"); |
| 68 | InstallTemplateURLWithNewTabPage(url_rewritten); |
| 69 | ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", |
| 70 | "Group1 use_cacheable_ntp:1")); |
| 71 | |
| 72 | AddTab(browser(), GURL("chrome://blank")); |
| 73 | NavigateAndCommitActiveTab(url_original); |
| 74 | |
| 75 | NavigationEntry* entry = browser()->tab_strip_model()-> |
| 76 | GetActiveWebContents()->GetController().GetLastCommittedEntry(); |
| 77 | ASSERT_TRUE(entry != NULL); |
| 78 | EXPECT_EQ(url_rewritten, entry->GetURL()); |
| 79 | EXPECT_EQ(url_original, entry->GetVirtualURL()); |
| 80 | } |
| 81 | |
| 82 | } // namespace content |
| 83 | #endif // !defined(OS_IOS) && !defined(OS_ANDROID) |