Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / extensions / api / settings_overrides / settings_overrides_browsertest.cc
blobd1ffe87f532608a61d566e32411cc471af9bbdf9
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 "base/prefs/pref_service.h"
6 #include "base/run_loop.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/extensions/extension_browsertest.h"
9 #include "chrome/browser/prefs/session_startup_pref.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/search_engines/template_url_service_factory.h"
12 #include "chrome/common/pref_names.h"
13 #include "components/search_engines/template_url.h"
14 #include "components/search_engines/template_url_service.h"
16 namespace {
18 class TemplateURLServiceObserver {
19 public:
20 TemplateURLServiceObserver(TemplateURLService* service,
21 base::RunLoop* loop)
22 : runner_(loop) {
23 DCHECK(loop);
24 template_url_sub_ = service->RegisterOnLoadedCallback(
25 base::Bind(&TemplateURLServiceObserver::StopLoop,
26 base::Unretained(this)));
27 service->Load();
29 ~TemplateURLServiceObserver() {}
31 private:
32 void StopLoop() {
33 runner_->Quit();
35 base::RunLoop* runner_;
36 scoped_ptr<TemplateURLService::Subscription> template_url_sub_;
38 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceObserver);
41 testing::AssertionResult VerifyTemplateURLServiceLoad(
42 TemplateURLService* service) {
43 if (service->loaded())
44 return testing::AssertionSuccess();
45 base::RunLoop runner;
46 TemplateURLServiceObserver observer(service, &runner);
47 runner.Run();
48 if (service->loaded())
49 return testing::AssertionSuccess();
50 return testing::AssertionFailure() << "TemplateURLService isn't loaded";
53 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, OverrideSettings) {
54 PrefService* prefs = profile()->GetPrefs();
55 ASSERT_TRUE(prefs);
56 prefs->SetString(prefs::kHomePage, "http://google.com/");
57 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, true);
58 const GURL urls[] = {GURL("http://foo"), GURL("http://bar")};
59 SessionStartupPref startup_pref(SessionStartupPref::LAST);
60 startup_pref.urls.assign(urls, urls + arraysize(urls));
61 SessionStartupPref::SetStartupPref(prefs, startup_pref);
62 TemplateURLService* url_service =
63 TemplateURLServiceFactory::GetForProfile(profile());
64 ASSERT_TRUE(url_service);
65 EXPECT_TRUE(VerifyTemplateURLServiceLoad(url_service));
66 TemplateURL* default_provider = url_service->GetDefaultSearchProvider();
67 ASSERT_TRUE(default_provider);
68 EXPECT_EQ(TemplateURL::NORMAL, default_provider->GetType());
70 #if defined(OS_WIN)
71 const extensions::Extension* extension = LoadExtensionWithInstallParam(
72 test_data_dir_.AppendASCII("settings_override"),
73 kFlagEnableFileAccess,
74 "10");
75 ASSERT_TRUE(extension);
76 EXPECT_EQ("http://www.homepage.de/?param=10",
77 prefs->GetString(prefs::kHomePage));
78 EXPECT_FALSE(prefs->GetBoolean(prefs::kHomePageIsNewTabPage));
79 startup_pref = SessionStartupPref::GetStartupPref(prefs);
80 EXPECT_EQ(SessionStartupPref::URLS, startup_pref.type);
81 EXPECT_EQ(std::vector<GURL>(1, GURL("http://www.startup.de/?param=10")),
82 startup_pref.urls);
83 TemplateURL* extension_provider = url_service->GetDefaultSearchProvider();
84 EXPECT_EQ(TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION,
85 extension_provider->GetType());
86 EXPECT_EQ(base::ASCIIToUTF16("name.de"), extension_provider->short_name());
87 EXPECT_EQ(base::ASCIIToUTF16("keyword.de"), extension_provider->keyword());
88 EXPECT_EQ("http://www.foo.de/s?q={searchTerms}&id=10",
89 extension_provider->url());
90 EXPECT_EQ(GURL("http://www.foo.de/favicon.ico?id=10"),
91 extension_provider->favicon_url());
92 EXPECT_EQ("http://www.foo.de/suggest?q={searchTerms}&id=10",
93 extension_provider->suggestions_url());
94 EXPECT_EQ("http://www.foo.de/instant?q={searchTerms}&id=10",
95 extension_provider->instant_url());
96 EXPECT_EQ("http://www.foo.de/image?q={searchTerms}&id=10",
97 extension_provider->image_url());
98 EXPECT_EQ("search_lang=de", extension_provider->search_url_post_params());
99 EXPECT_EQ("suggest_lang=de",
100 extension_provider->suggestions_url_post_params());
101 EXPECT_EQ("instant_lang=de", extension_provider->instant_url_post_params());
102 EXPECT_EQ("image_lang=de", extension_provider->image_url_post_params());
103 const std::string alternate_urls[] = {
104 "http://www.moo.de/s?q={searchTerms}&id=10",
105 "http://www.noo.de/s?q={searchTerms}&id=10"};
106 EXPECT_EQ(std::vector<std::string>(
107 alternate_urls, alternate_urls + arraysize(alternate_urls)),
108 extension_provider->alternate_urls());
109 EXPECT_EQ(std::vector<std::string>(1, "UTF-8"),
110 extension_provider->input_encodings());
111 EXPECT_EQ(default_provider->new_tab_url(), extension_provider->new_tab_url());
113 UnloadExtension(extension->id());
114 EXPECT_EQ("http://google.com/", prefs->GetString(prefs::kHomePage));
115 EXPECT_TRUE(prefs->GetBoolean(prefs::kHomePageIsNewTabPage));
116 startup_pref = SessionStartupPref::GetStartupPref(prefs);
117 EXPECT_EQ(SessionStartupPref::LAST, startup_pref.type);
118 EXPECT_EQ(std::vector<GURL>(urls, urls + arraysize(urls)), startup_pref.urls);
119 EXPECT_EQ(default_provider, url_service->GetDefaultSearchProvider());
120 #else
121 const extensions::Extension* extension =
122 LoadExtensionWithFlags(test_data_dir_.AppendASCII("settings_override"),
123 kFlagIgnoreManifestWarnings);
124 ASSERT_TRUE(extension);
125 ASSERT_EQ(1u, extension->install_warnings().size());
126 EXPECT_EQ(std::string(
127 "'chrome_settings_overrides' "
128 "is not allowed for specified platform."),
129 extension->install_warnings().front().message);
130 #endif
133 } // namespace