| OLD | NEW |
| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 #include "content/public/common/url_constants.h" | 50 #include "content/public/common/url_constants.h" |
| 51 #include "content/public/test/browser_test_utils.h" | 51 #include "content/public/test/browser_test_utils.h" |
| 52 #include "content/public/test/test_utils.h" | 52 #include "content/public/test/test_utils.h" |
| 53 #include "google_apis/gaia/google_service_auth_error.h" | 53 #include "google_apis/gaia/google_service_auth_error.h" |
| 54 #include "testing/gmock/include/gmock/gmock.h" | 54 #include "testing/gmock/include/gmock/gmock.h" |
| 55 #include "testing/gtest/include/gtest/gtest.h" | 55 #include "testing/gtest/include/gtest/gtest.h" |
| 56 #include "third_party/WebKit/public/web/WebInputEvent.h" | 56 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 57 #include "ui/base/window_open_disposition.h" | 57 #include "ui/base/window_open_disposition.h" |
| 58 #include "url/gurl.h" | 58 #include "url/gurl.h" |
| 59 | 59 |
| 60 #if defined(OS_MACOSX) |
| 61 #include "base/mac/mac_util.h" |
| 62 #include "base/mac/scoped_nsautorelease_pool.h" |
| 63 #include "chrome/browser/ui/cocoa/run_loop_testing.h" |
| 64 #endif |
| 65 |
| 60 namespace autofill { | 66 namespace autofill { |
| 61 | 67 |
| 62 namespace { | 68 namespace { |
| 63 | 69 |
| 64 using testing::_; | 70 using testing::_; |
| 65 | 71 |
| 66 void MockCallback(const FormStructure*) {} | 72 void MockCallback(const FormStructure*) {} |
| 67 | 73 |
| 68 class MockAutofillMetrics : public AutofillMetrics { | 74 class MockAutofillMetrics : public AutofillMetrics { |
| 69 public: | 75 public: |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 class AutofillDialogControllerTest : public InProcessBrowserTest { | 281 class AutofillDialogControllerTest : public InProcessBrowserTest { |
| 276 public: | 282 public: |
| 277 AutofillDialogControllerTest() {} | 283 AutofillDialogControllerTest() {} |
| 278 virtual ~AutofillDialogControllerTest() {} | 284 virtual ~AutofillDialogControllerTest() {} |
| 279 | 285 |
| 280 virtual void SetUpOnMainThread() OVERRIDE { | 286 virtual void SetUpOnMainThread() OVERRIDE { |
| 281 autofill::test::DisableSystemServices(browser()->profile()); | 287 autofill::test::DisableSystemServices(browser()->profile()); |
| 282 InitializeController(); | 288 InitializeController(); |
| 283 } | 289 } |
| 284 | 290 |
| 291 // A helper function that cycles the MessageLoop, and on Mac, the Cocoa run |
| 292 // loop. It also drains the NSAutoreleasePool. |
| 293 void CycleRunLoops() { |
| 294 content::RunAllPendingInMessageLoop(); |
| 295 #if defined(OS_MACOSX) |
| 296 chrome::testing::NSRunLoopRunAllPending(); |
| 297 AutoreleasePool()->Recycle(); |
| 298 #endif |
| 299 } |
| 300 |
| 285 void InitializeController() { | 301 void InitializeController() { |
| 286 FormData form; | 302 FormData form; |
| 287 form.name = ASCIIToUTF16("TestForm"); | 303 form.name = ASCIIToUTF16("TestForm"); |
| 288 form.method = ASCIIToUTF16("POST"); | 304 form.method = ASCIIToUTF16("POST"); |
| 289 form.origin = GURL("http://example.com/form.html"); | 305 form.origin = GURL("http://example.com/form.html"); |
| 290 form.action = GURL("http://example.com/submit.html"); | 306 form.action = GURL("http://example.com/submit.html"); |
| 291 form.user_submitted = true; | 307 form.user_submitted = true; |
| 292 | 308 |
| 293 FormFieldData field; | 309 FormFieldData field; |
| 294 field.autocomplete_attribute = "shipping tel"; | 310 field.autocomplete_attribute = "shipping tel"; |
| 295 form.fields.push_back(field); | 311 form.fields.push_back(field); |
| 296 | 312 |
| 297 test_generated_bubble_controller_ = | 313 test_generated_bubble_controller_ = |
| 298 new testing::NiceMock<TestGeneratedCreditCardBubbleController>( | 314 new testing::NiceMock<TestGeneratedCreditCardBubbleController>( |
| 299 GetActiveWebContents()); | 315 GetActiveWebContents()); |
| 300 ASSERT_TRUE(test_generated_bubble_controller_->IsInstalled()); | 316 ASSERT_TRUE(test_generated_bubble_controller_->IsInstalled()); |
| 301 | 317 |
| 302 message_loop_runner_ = new content::MessageLoopRunner; | 318 message_loop_runner_ = new content::MessageLoopRunner; |
| 303 controller_ = new TestAutofillDialogController( | 319 controller_ = new TestAutofillDialogController( |
| 304 GetActiveWebContents(), | 320 GetActiveWebContents(), |
| 305 form, | 321 form, |
| 306 metric_logger_, | 322 metric_logger_, |
| 307 message_loop_runner_); | 323 message_loop_runner_); |
| 308 controller_->Show(); | 324 controller_->Show(); |
| 325 CycleRunLoops(); // Ensures dialog is fully visible. |
| 309 } | 326 } |
| 310 | 327 |
| 311 content::WebContents* GetActiveWebContents() { | 328 content::WebContents* GetActiveWebContents() { |
| 312 return browser()->tab_strip_model()->GetActiveWebContents(); | 329 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 313 } | 330 } |
| 314 | 331 |
| 315 const MockAutofillMetrics& metric_logger() { return metric_logger_; } | 332 const MockAutofillMetrics& metric_logger() { return metric_logger_; } |
| 316 TestAutofillDialogController* controller() { return controller_; } | 333 TestAutofillDialogController* controller() { return controller_; } |
| 317 | 334 |
| 318 void RunMessageLoop() { | 335 void RunMessageLoop() { |
| (...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 content::Referrer(), | 1262 content::Referrer(), |
| 1246 CURRENT_TAB, | 1263 CURRENT_TAB, |
| 1247 content::PAGE_TRANSITION_LINK, | 1264 content::PAGE_TRANSITION_LINK, |
| 1248 true); | 1265 true); |
| 1249 int num_tabs = browser()->tab_strip_model()->count(); | 1266 int num_tabs = browser()->tab_strip_model()->count(); |
| 1250 sign_in_contents->GetDelegate()->OpenURLFromTab(sign_in_contents, params); | 1267 sign_in_contents->GetDelegate()->OpenURLFromTab(sign_in_contents, params); |
| 1251 EXPECT_EQ(num_tabs + 1, browser()->tab_strip_model()->count()); | 1268 EXPECT_EQ(num_tabs + 1, browser()->tab_strip_model()->count()); |
| 1252 } | 1269 } |
| 1253 | 1270 |
| 1254 } // namespace autofill | 1271 } // namespace autofill |
| OLD | NEW |