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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comments Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/guid.h" 5 #include "base/guid.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/run_loop.h"
9 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" 11 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
11 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" 12 #include "chrome/browser/ui/autofill/autofill_dialog_view.h"
12 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
13 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
14 #include "components/autofill/browser/autofill_common_test.h" 15 #include "components/autofill/browser/autofill_common_test.h"
15 #include "components/autofill/browser/autofill_metrics.h" 16 #include "components/autofill/browser/autofill_metrics.h"
16 #include "components/autofill/browser/test_personal_data_manager.h" 17 #include "components/autofill/browser/test_personal_data_manager.h"
17 #include "components/autofill/browser/wallet/full_wallet.h" 18 #include "components/autofill/browser/wallet/full_wallet.h"
18 #include "components/autofill/browser/wallet/instrument.h" 19 #include "components/autofill/browser/wallet/instrument.h"
19 #include "components/autofill/browser/wallet/wallet_address.h" 20 #include "components/autofill/browser/wallet/wallet_address.h"
20 #include "components/autofill/browser/wallet/wallet_client.h" 21 #include "components/autofill/browser/wallet/wallet_client.h"
21 #include "components/autofill/browser/wallet/wallet_test_util.h" 22 #include "components/autofill/browser/wallet/wallet_test_util.h"
22 #include "components/autofill/common/form_data.h" 23 #include "components/autofill/common/form_data.h"
23 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
24 #include "content/public/test/test_browser_thread.h" 25 #include "content/public/test/test_browser_thread_bundle.h"
25 #include "content/public/test/web_contents_tester.h" 26 #include "content/public/test/web_contents_tester.h"
26 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 29
29 #if defined(OS_WIN) 30 #if defined(OS_WIN)
30 #include "ui/base/win/scoped_ole_initializer.h" 31 #include "ui/base/win/scoped_ole_initializer.h"
31 #endif 32 #endif
32 33
33 using testing::_; 34 using testing::_;
34 35
35 namespace autofill { 36 namespace autofill {
36 37
37 namespace { 38 namespace {
38 39
39 const char kFakeEmail[] = "user@example.com"; 40 const char kFakeEmail[] = "user@example.com";
40 const char kEditedBillingAddress[] = "123 edited billing address"; 41 const char kEditedBillingAddress[] = "123 edited billing address";
41 const char* kFieldsFromPage[] = { "email", "cc-number", "billing region", 42 const char* kFieldsFromPage[] = { "email", "cc-number", "billing region",
42 "shipping region" }; 43 "shipping region" };
43 const char kSettingsOrigin[] = "Chrome settings"; 44 const char kSettingsOrigin[] = "Chrome settings";
44 45
45 using content::BrowserThread;
46
47 class TestAutofillDialogView : public AutofillDialogView { 46 class TestAutofillDialogView : public AutofillDialogView {
48 public: 47 public:
49 TestAutofillDialogView() {} 48 TestAutofillDialogView() {}
50 virtual ~TestAutofillDialogView() {} 49 virtual ~TestAutofillDialogView() {}
51 50
52 virtual void Show() OVERRIDE {} 51 virtual void Show() OVERRIDE {}
53 virtual void Hide() OVERRIDE {} 52 virtual void Hide() OVERRIDE {}
54 virtual void UpdateNotificationArea() OVERRIDE {} 53 virtual void UpdateNotificationArea() OVERRIDE {}
55 virtual void UpdateAccountChooser() OVERRIDE {} 54 virtual void UpdateAccountChooser() OVERRIDE {}
56 virtual void UpdateButtonStrip() OVERRIDE {} 55 virtual void UpdateButtonStrip() OVERRIDE {}
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 const AutofillMetrics& metric_logger_; 226 const AutofillMetrics& metric_logger_;
228 TestPersonalDataManager test_manager_; 227 TestPersonalDataManager test_manager_;
229 testing::NiceMock<TestWalletClient> test_wallet_client_; 228 testing::NiceMock<TestWalletClient> test_wallet_client_;
230 bool is_first_run_; 229 bool is_first_run_;
231 GURL open_tab_url_; 230 GURL open_tab_url_;
232 231
233 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); 232 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController);
234 }; 233 };
235 234
236 class AutofillDialogControllerTest : public testing::Test { 235 class AutofillDialogControllerTest : public testing::Test {
237 public: 236 protected:
238 AutofillDialogControllerTest()
239 : ui_thread_(BrowserThread::UI, &loop_),
240 file_thread_(BrowserThread::FILE),
241 file_blocking_thread_(BrowserThread::FILE_USER_BLOCKING),
242 io_thread_(BrowserThread::IO) {
243 file_thread_.Start();
244 file_blocking_thread_.Start();
245 io_thread_.StartIOThread();
246 }
247
248 virtual ~AutofillDialogControllerTest() {}
249
250 // testing::Test implementation: 237 // testing::Test implementation:
251 virtual void SetUp() OVERRIDE { 238 virtual void SetUp() OVERRIDE {
252 FormData form_data; 239 FormData form_data;
253 for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) { 240 for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) {
254 FormFieldData field; 241 FormFieldData field;
255 field.autocomplete_attribute = kFieldsFromPage[i]; 242 field.autocomplete_attribute = kFieldsFromPage[i];
256 form_data.fields.push_back(field); 243 form_data.fields.push_back(field);
257 } 244 }
258 245
259 profile()->CreateRequestContext(); 246 profile()->CreateRequestContext();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 TestingProfile* profile() { return &profile_; } 313 TestingProfile* profile() { return &profile_; }
327 314
328 const FormStructure* form_structure() { return form_structure_; } 315 const FormStructure* form_structure() { return form_structure_; }
329 316
330 private: 317 private:
331 void FinishedCallback(const FormStructure* form_structure, 318 void FinishedCallback(const FormStructure* form_structure,
332 const std::string& google_transaction_id) { 319 const std::string& google_transaction_id) {
333 form_structure_ = form_structure; 320 form_structure_ = form_structure;
334 } 321 }
335 322
323 // Must be first member to ensure TestBrowserThreads outlive other objects.
324 content::TestBrowserThreadBundle thread_bundle_;
325
336 #if defined(OS_WIN) 326 #if defined(OS_WIN)
337 // http://crbug.com/227221 327 // http://crbug.com/227221
338 ui::ScopedOleInitializer ole_initializer_; 328 ui::ScopedOleInitializer ole_initializer_;
339 #endif 329 #endif
340 330
341 // A bunch of threads are necessary for classes like TestWebContents and
342 // URLRequestContextGetter not to fall over.
343 base::MessageLoopForUI loop_;
344 content::TestBrowserThread ui_thread_;
345 content::TestBrowserThread file_thread_;
346 content::TestBrowserThread file_blocking_thread_;
347 content::TestBrowserThread io_thread_;
348 TestingProfile profile_; 331 TestingProfile profile_;
349 332
350 // The controller owns itself. 333 // The controller owns itself.
351 base::WeakPtr<TestAutofillDialogController> controller_; 334 base::WeakPtr<TestAutofillDialogController> controller_;
352 335
353 scoped_ptr<content::WebContents> test_web_contents_; 336 scoped_ptr<content::WebContents> test_web_contents_;
354 337
355 // Must outlive the controller. 338 // Must outlive the controller.
356 AutofillMetrics metric_logger_; 339 AutofillMetrics metric_logger_;
357 340
358 // Returned when the dialog closes successfully. 341 // Returned when the dialog closes successfully.
359 const FormStructure* form_structure_; 342 const FormStructure* form_structure_;
360
361 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest);
Ilya Sherman 2013/05/20 21:38:49 Why did you remove this? I see in your CL descrip
awong 2013/05/20 21:57:56 Replied on main thread and added explanation to th
Ilya Sherman 2013/05/20 22:33:01 Ok, thanks for the explanation -- makes sense :)
362 }; 343 };
363 344
364 } // namespace 345 } // namespace
365 346
366 // This test makes sure nothing falls over when fields are being validity- 347 // This test makes sure nothing falls over when fields are being validity-
367 // checked. 348 // checked.
368 TEST_F(AutofillDialogControllerTest, ValidityCheck) { 349 TEST_F(AutofillDialogControllerTest, ValidityCheck) {
369 const DialogSection sections[] = { 350 const DialogSection sections[] = {
370 SECTION_EMAIL, 351 SECTION_EMAIL,
371 SECTION_CC, 352 SECTION_CC,
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 1145 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
1165 1146
1166 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); 1147 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1);
1167 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); 1148 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome());
1168 1149
1169 profile()->set_incognito(true); 1150 profile()->set_incognito(true);
1170 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 1151 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
1171 } 1152 }
1172 1153
1173 } // namespace autofill 1154 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698