Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: chrome/browser/ui/browser_instant_controller_unittest.cc

Issue 2606293002: Remove ScopedVector from chrome/browser/ui. (Closed)
Patch Set: view Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/gtest_prod_util.h" 7 #include "base/gtest_prod_util.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
11 #include "base/run_loop.h" 10 #include "base/run_loop.h"
12 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/search/instant_service.h" 12 #include "chrome/browser/search/instant_service.h"
14 #include "chrome/browser/search/instant_service_observer.h" 13 #include "chrome/browser/search/instant_service_observer.h"
15 #include "chrome/browser/search/instant_unittest_base.h" 14 #include "chrome/browser/search/instant_unittest_base.h"
16 #include "chrome/browser/search/search.h" 15 #include "chrome/browser/search/search.h"
17 #include "chrome/browser/ui/browser_instant_controller.h" 16 #include "chrome/browser/ui/browser_instant_controller.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 108
110 private: 109 private:
111 content::WebContents* contents_; 110 content::WebContents* contents_;
112 const GURL& url_; 111 const GURL& url_;
113 GURL current_url_; 112 GURL current_url_;
114 int num_reloads_; 113 int num_reloads_;
115 }; 114 };
116 115
117 TEST_F(BrowserInstantControllerTest, DefaultSearchProviderChanged) { 116 TEST_F(BrowserInstantControllerTest, DefaultSearchProviderChanged) {
118 size_t num_tests = arraysize(kTabReloadTestCasesFinalProviderNotGoogle); 117 size_t num_tests = arraysize(kTabReloadTestCasesFinalProviderNotGoogle);
119 ScopedVector<FakeWebContentsObserver> observers; 118 std::vector<std::unique_ptr<FakeWebContentsObserver>> observers;
120 for (size_t i = 0; i < num_tests; ++i) { 119 for (size_t i = 0; i < num_tests; ++i) {
121 const TabReloadTestCase& test = 120 const TabReloadTestCase& test =
122 kTabReloadTestCasesFinalProviderNotGoogle[i]; 121 kTabReloadTestCasesFinalProviderNotGoogle[i];
123 AddTab(browser(), GURL(test.start_url)); 122 AddTab(browser(), GURL(test.start_url));
124 content::WebContents* contents = 123 content::WebContents* contents =
125 browser()->tab_strip_model()->GetActiveWebContents(); 124 browser()->tab_strip_model()->GetActiveWebContents();
126 125
127 // Validate initial instant state. 126 // Validate initial instant state.
128 EXPECT_EQ(test.start_in_instant_process, 127 EXPECT_EQ(test.start_in_instant_process,
129 instant_service_->IsInstantProcess( 128 instant_service_->IsInstantProcess(
130 contents->GetRenderProcessHost()->GetID())) 129 contents->GetRenderProcessHost()->GetID()))
131 << test.description; 130 << test.description;
132 131
133 // Setup an observer to verify reload or absence thereof. 132 // Setup an observer to verify reload or absence thereof.
134 observers.push_back(new FakeWebContentsObserver(contents)); 133 observers.push_back(base::MakeUnique<FakeWebContentsObserver>(contents));
135 } 134 }
136 135
137 SetUserSelectedDefaultSearchProvider("https://bar.com/"); 136 SetUserSelectedDefaultSearchProvider("https://bar.com/");
138 137
139 for (size_t i = 0; i < num_tests; ++i) { 138 for (size_t i = 0; i < num_tests; ++i) {
140 FakeWebContentsObserver* observer = observers[i]; 139 FakeWebContentsObserver* observer = observers[i].get();
141 const TabReloadTestCase& test = 140 const TabReloadTestCase& test =
142 kTabReloadTestCasesFinalProviderNotGoogle[i]; 141 kTabReloadTestCasesFinalProviderNotGoogle[i];
143 142
144 if (test.should_reload) { 143 if (test.should_reload) {
145 // Validate final instant state. 144 // Validate final instant state.
146 EXPECT_EQ(test.end_in_instant_process, 145 EXPECT_EQ(test.end_in_instant_process,
147 search::ShouldAssignURLToInstantRenderer( 146 search::ShouldAssignURLToInstantRenderer(
148 observer->current_url(), profile())) 147 observer->current_url(), profile()))
149 << test.description; 148 << test.description;
150 } 149 }
151 150
152 // Ensure only the expected tabs(contents) reloaded. 151 // Ensure only the expected tabs(contents) reloaded.
153 base::RunLoop loop; 152 base::RunLoop loop;
154 loop.RunUntilIdle(); 153 loop.RunUntilIdle();
155 EXPECT_EQ(test.should_reload ? 1 : 0, observer->num_reloads()) 154 EXPECT_EQ(test.should_reload ? 1 : 0, observer->num_reloads())
156 << test.description; 155 << test.description;
157 156
158 if (test.end_in_local_ntp) { 157 if (test.end_in_local_ntp) {
159 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), observer->current_url()) 158 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), observer->current_url())
160 << test.description; 159 << test.description;
161 } 160 }
162 } 161 }
163 } 162 }
164 163
165 TEST_F(BrowserInstantControllerTest, GoogleBaseURLUpdated) { 164 TEST_F(BrowserInstantControllerTest, GoogleBaseURLUpdated) {
166 const size_t num_tests = arraysize(kTabReloadTestCasesFinalProviderGoogle); 165 const size_t num_tests = arraysize(kTabReloadTestCasesFinalProviderGoogle);
167 ScopedVector<FakeWebContentsObserver> observers; 166 std::vector<std::unique_ptr<FakeWebContentsObserver>> observers;
168 for (size_t i = 0; i < num_tests; ++i) { 167 for (size_t i = 0; i < num_tests; ++i) {
169 const TabReloadTestCase& test = kTabReloadTestCasesFinalProviderGoogle[i]; 168 const TabReloadTestCase& test = kTabReloadTestCasesFinalProviderGoogle[i];
170 AddTab(browser(), GURL(test.start_url)); 169 AddTab(browser(), GURL(test.start_url));
171 content::WebContents* contents = 170 content::WebContents* contents =
172 browser()->tab_strip_model()->GetActiveWebContents(); 171 browser()->tab_strip_model()->GetActiveWebContents();
173 172
174 // Validate initial instant state. 173 // Validate initial instant state.
175 EXPECT_EQ(test.start_in_instant_process, 174 EXPECT_EQ(test.start_in_instant_process,
176 instant_service_->IsInstantProcess( 175 instant_service_->IsInstantProcess(
177 contents->GetRenderProcessHost()->GetID())) 176 contents->GetRenderProcessHost()->GetID()))
178 << test.description; 177 << test.description;
179 178
180 // Setup an observer to verify reload or absence thereof. 179 // Setup an observer to verify reload or absence thereof.
181 observers.push_back(new FakeWebContentsObserver(contents)); 180 observers.push_back(base::MakeUnique<FakeWebContentsObserver>(contents));
182 } 181 }
183 182
184 NotifyGoogleBaseURLUpdate("https://www.google.es/"); 183 NotifyGoogleBaseURLUpdate("https://www.google.es/");
185 184
186 for (size_t i = 0; i < num_tests; ++i) { 185 for (size_t i = 0; i < num_tests; ++i) {
187 const TabReloadTestCase& test = kTabReloadTestCasesFinalProviderGoogle[i]; 186 const TabReloadTestCase& test = kTabReloadTestCasesFinalProviderGoogle[i];
188 FakeWebContentsObserver* observer = observers[i]; 187 FakeWebContentsObserver* observer = observers[i].get();
189 188
190 // Validate final instant state. 189 // Validate final instant state.
191 EXPECT_EQ(test.end_in_instant_process, 190 EXPECT_EQ(test.end_in_instant_process,
192 search::ShouldAssignURLToInstantRenderer(observer->current_url(), 191 search::ShouldAssignURLToInstantRenderer(observer->current_url(),
193 profile())) 192 profile()))
194 << test.description; 193 << test.description;
195 194
196 // Ensure only the expected tabs(contents) reloaded. 195 // Ensure only the expected tabs(contents) reloaded.
197 base::RunLoop loop; 196 base::RunLoop loop;
198 loop.RunUntilIdle(); 197 loop.RunUntilIdle();
(...skipping 21 matching lines...) Expand all
220 219
221 browser.reset(NULL); 220 browser.reset(NULL);
222 window.reset(NULL); 221 window.reset(NULL);
223 EXPECT_FALSE(IsInstantServiceObserver(bic)) 222 EXPECT_FALSE(IsInstantServiceObserver(bic))
224 << "New BrowserInstantController should register as InstantServiceObserver"; 223 << "New BrowserInstantController should register as InstantServiceObserver";
225 } 224 }
226 225
227 } // namespace 226 } // namespace
228 227
229 } // namespace chrome 228 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698