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/instant/instant_test_utils.h" | 5 #include "chrome/browser/instant/instant_test_utils.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/search_engines/template_url_service.h" | 10 #include "chrome/browser/search_engines/template_url_service.h" |
11 #include "chrome/browser/search_engines/template_url_service_factory.h" | 11 #include "chrome/browser/search_engines/template_url_service_factory.h" |
12 #include "chrome/common/chrome_switches.h" | |
13 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
14 #include "chrome/test/base/interactive_test_utils.h" | 13 #include "chrome/test/base/interactive_test_utils.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
16 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
18 #include "content/public/common/result_codes.h" | 17 #include "content/public/common/result_codes.h" |
19 #include "content/public/test/browser_test_utils.h" | 18 #include "content/public/test/browser_test_utils.h" |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
(...skipping 22 matching lines...) Expand all Loading... |
45 } | 44 } |
46 | 45 |
47 void InstantTestModelObserver::PreviewStateChanged(const InstantModel& model) { | 46 void InstantTestModelObserver::PreviewStateChanged(const InstantModel& model) { |
48 if (model.mode().mode == desired_mode_type_) | 47 if (model.mode().mode == desired_mode_type_) |
49 run_loop_.Quit(); | 48 run_loop_.Quit(); |
50 } | 49 } |
51 | 50 |
52 // InstantTestBase ----------------------------------------------------------- | 51 // InstantTestBase ----------------------------------------------------------- |
53 | 52 |
54 void InstantTestBase::SetupInstant() { | 53 void InstantTestBase::SetupInstant() { |
55 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
56 switches::kInstantURL, instant_url_.spec()); | |
57 SetupInstantUsingTemplateURL(); | |
58 | |
59 // TODO(shishir): Fix this ugly hack. | |
60 instant()->SetInstantEnabled(false, true); | |
61 instant()->SetInstantEnabled(true, false); | |
62 } | |
63 | |
64 void InstantTestBase::SetupInstantUsingTemplateURL() { | |
65 TemplateURLService* service = | 54 TemplateURLService* service = |
66 TemplateURLServiceFactory::GetForProfile(browser()->profile()); | 55 TemplateURLServiceFactory::GetForProfile(browser()->profile()); |
67 ui_test_utils::WaitForTemplateURLServiceToLoad(service); | 56 ui_test_utils::WaitForTemplateURLServiceToLoad(service); |
68 | 57 |
69 TemplateURLData data; | 58 TemplateURLData data; |
70 // Necessary to use exact URL for both the main URL and the alternate URL for | 59 // Necessary to use exact URL for both the main URL and the alternate URL for |
71 // search term extraction to work in InstantExtended. | 60 // search term extraction to work in InstantExtended. |
72 data.SetURL(instant_url_.spec() + "q={searchTerms}"); | 61 data.SetURL(instant_url_.spec() + "q={searchTerms}"); |
73 data.instant_url = instant_url_.spec(); | 62 data.instant_url = instant_url_.spec(); |
74 data.alternate_urls.push_back(instant_url_.spec() + "#q={searchTerms}"); | 63 data.alternate_urls.push_back(instant_url_.spec() + "#q={searchTerms}"); |
75 data.search_terms_replacement_key = "strk"; | 64 data.search_terms_replacement_key = "strk"; |
76 | 65 |
77 TemplateURL* template_url = new TemplateURL(browser()->profile(), data); | 66 TemplateURL* template_url = new TemplateURL(browser()->profile(), data); |
78 service->Add(template_url); // Takes ownership of |template_url|. | 67 service->Add(template_url); // Takes ownership of |template_url|. |
79 service->SetDefaultSearchProvider(template_url); | 68 service->SetDefaultSearchProvider(template_url); |
| 69 |
80 browser()->profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true); | 70 browser()->profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true); |
| 71 |
| 72 // TODO(shishir): Fix this ugly hack. |
| 73 instant()->SetInstantEnabled(false, true); |
| 74 instant()->SetInstantEnabled(true, false); |
81 } | 75 } |
82 | 76 |
83 void InstantTestBase::KillInstantRenderView() { | 77 void InstantTestBase::KillInstantRenderView() { |
84 base::KillProcess( | 78 base::KillProcess( |
85 instant()->GetPreviewContents()->GetRenderProcessHost()->GetHandle(), | 79 instant()->GetPreviewContents()->GetRenderProcessHost()->GetHandle(), |
86 content::RESULT_CODE_KILLED, | 80 content::RESULT_CODE_KILLED, |
87 false); | 81 false); |
88 } | 82 } |
89 | 83 |
90 void InstantTestBase::FocusOmnibox() { | 84 void InstantTestBase::FocusOmnibox() { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 130 } |
137 | 131 |
138 bool InstantTestBase::CheckVisibilityIs(content::WebContents* contents, | 132 bool InstantTestBase::CheckVisibilityIs(content::WebContents* contents, |
139 bool expected) { | 133 bool expected) { |
140 bool actual = !expected; // Purposely start with a mis-match. | 134 bool actual = !expected; // Purposely start with a mis-match. |
141 // We can only use ASSERT_*() in a method that returns void, hence this | 135 // We can only use ASSERT_*() in a method that returns void, hence this |
142 // convoluted check. | 136 // convoluted check. |
143 return GetBoolFromJS(contents, "!document.webkitHidden", &actual) && | 137 return GetBoolFromJS(contents, "!document.webkitHidden", &actual) && |
144 actual == expected; | 138 actual == expected; |
145 } | 139 } |
OLD | NEW |