Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chrome_content_browser_client_unittest.cc
blob6e7d2e5c4dbca203a169c08b1d1001711e7df896
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.
5 #include "chrome/browser/chrome_content_browser_client.h"
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"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "url/gurl.h"
21 namespace chrome {
23 typedef testing::Test ChromeContentBrowserClientTest;
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")));
33 } // namespace chrome
35 #if !defined(OS_IOS) && !defined(OS_ANDROID)
36 namespace content {
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")));
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);
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);
62 scoped_ptr<base::FieldTrialList> field_trial_list_;
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"));
72 AddTab(browser(), GURL("chrome://blank"));
73 NavigateAndCommitActiveTab(url_original);
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());
82 } // namespace content
83 #endif // !defined(OS_IOS) && !defined(OS_ANDROID)