| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 124 |
| 125 // AddProfile is asynchronous. Wait for it to finish before continuing the | 125 // AddProfile is asynchronous. Wait for it to finish before continuing the |
| 126 // tests. | 126 // tests. |
| 127 observer.Wait(); | 127 observer.Wait(); |
| 128 personal_data_manager->RemoveObserver(&observer); | 128 personal_data_manager->RemoveObserver(&observer); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void ExpectFieldValue(const std::wstring& field_name, | 131 void ExpectFieldValue(const std::wstring& field_name, |
| 132 const std::string& expected_value) { | 132 const std::string& expected_value) { |
| 133 std::string value; | 133 std::string value; |
| 134 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 134 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| 135 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 135 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 136 L"window.domAutomationController.send(" | 136 L"window.domAutomationController.send(" |
| 137 L"document.getElementById('" + field_name + L"').value);", &value)); | 137 L"document.getElementById('" + field_name + L"').value);", &value)); |
| 138 EXPECT_EQ(expected_value, value); | 138 EXPECT_EQ(expected_value, value); |
| 139 } | 139 } |
| 140 | 140 |
| 141 RenderViewHost* render_view_host() { | 141 RenderViewHost* render_view_host() { |
| 142 return chrome::GetActiveWebContents(browser())->GetRenderViewHost(); | 142 return chrome::GetActiveWebContents(browser())->GetRenderViewHost(); |
| 143 } | 143 } |
| 144 | 144 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 fetcher->SetResponseString(script); | 181 fetcher->SetResponseString(script); |
| 182 fetcher->delegate()->OnURLFetchComplete(fetcher); | 182 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void FocusFirstNameField() { | 185 void FocusFirstNameField() { |
| 186 LOG(WARNING) << "Clicking on the tab."; | 186 LOG(WARNING) << "Clicking on the tab."; |
| 187 content::SimulateMouseClick(chrome::GetActiveWebContents(browser())); | 187 content::SimulateMouseClick(chrome::GetActiveWebContents(browser())); |
| 188 | 188 |
| 189 LOG(WARNING) << "Focusing the first name field."; | 189 LOG(WARNING) << "Focusing the first name field."; |
| 190 bool result = false; | 190 bool result = false; |
| 191 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 191 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 192 render_view_host(), L"", | 192 render_view_host(), L"", |
| 193 L"if (document.readyState === 'complete')" | 193 L"if (document.readyState === 'complete')" |
| 194 L" document.getElementById('firstname').focus();" | 194 L" document.getElementById('firstname').focus();" |
| 195 L"else" | 195 L"else" |
| 196 L" domAutomationController.send(false);", | 196 L" domAutomationController.send(false);", |
| 197 &result)); | 197 &result)); |
| 198 ASSERT_TRUE(result); | 198 ASSERT_TRUE(result); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void ExpectFilledTestForm() { | 201 void ExpectFilledTestForm() { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 // The form should be filled. | 351 // The form should be filled. |
| 352 ExpectFilledTestForm(); | 352 ExpectFilledTestForm(); |
| 353 | 353 |
| 354 // The change event should have already fired for unfocused fields, both of | 354 // The change event should have already fired for unfocused fields, both of |
| 355 // <input> and of <select> type. However, it should not yet have fired for the | 355 // <input> and of <select> type. However, it should not yet have fired for the |
| 356 // focused field. | 356 // focused field. |
| 357 bool focused_fired = false; | 357 bool focused_fired = false; |
| 358 bool unfocused_fired = false; | 358 bool unfocused_fired = false; |
| 359 bool changed_select_fired = false; | 359 bool changed_select_fired = false; |
| 360 bool unchanged_select_fired = false; | 360 bool unchanged_select_fired = false; |
| 361 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 361 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 362 render_view_host(), L"", | 362 render_view_host(), L"", |
| 363 L"domAutomationController.send(focused_fired);", &focused_fired)); | 363 L"domAutomationController.send(focused_fired);", &focused_fired)); |
| 364 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 364 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 365 render_view_host(), L"", | 365 render_view_host(), L"", |
| 366 L"domAutomationController.send(unfocused_fired);", &unfocused_fired)); | 366 L"domAutomationController.send(unfocused_fired);", &unfocused_fired)); |
| 367 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 367 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 368 render_view_host(), L"", | 368 render_view_host(), L"", |
| 369 L"domAutomationController.send(changed_select_fired);", | 369 L"domAutomationController.send(changed_select_fired);", |
| 370 &changed_select_fired)); | 370 &changed_select_fired)); |
| 371 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 371 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 372 render_view_host(), L"", | 372 render_view_host(), L"", |
| 373 L"domAutomationController.send(unchanged_select_fired);", | 373 L"domAutomationController.send(unchanged_select_fired);", |
| 374 &unchanged_select_fired)); | 374 &unchanged_select_fired)); |
| 375 EXPECT_FALSE(focused_fired); | 375 EXPECT_FALSE(focused_fired); |
| 376 EXPECT_TRUE(unfocused_fired); | 376 EXPECT_TRUE(unfocused_fired); |
| 377 EXPECT_TRUE(changed_select_fired); | 377 EXPECT_TRUE(changed_select_fired); |
| 378 EXPECT_FALSE(unchanged_select_fired); | 378 EXPECT_FALSE(unchanged_select_fired); |
| 379 | 379 |
| 380 // Unfocus the first name field. Its change event should fire. | 380 // Unfocus the first name field. Its change event should fire. |
| 381 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 381 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 382 render_view_host(), L"", | 382 render_view_host(), L"", |
| 383 L"document.getElementById('firstname').blur();" | 383 L"document.getElementById('firstname').blur();" |
| 384 L"domAutomationController.send(focused_fired);", &focused_fired)); | 384 L"domAutomationController.send(focused_fired);", &focused_fired)); |
| 385 EXPECT_TRUE(focused_fired); | 385 EXPECT_TRUE(focused_fired); |
| 386 } | 386 } |
| 387 | 387 |
| 388 // Test that we can autofill forms distinguished only by their |id| attribute. | 388 // Test that we can autofill forms distinguished only by their |id| attribute. |
| 389 IN_PROC_BROWSER_TEST_F(AutofillTest, AutofillFormsDistinguishedById) { | 389 IN_PROC_BROWSER_TEST_F(AutofillTest, AutofillFormsDistinguishedById) { |
| 390 CreateTestProfile(); | 390 CreateTestProfile(); |
| 391 | 391 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 "" | 586 "" |
| 587 " for (var i = 0; i < elements.length; i++) {" | 587 " for (var i = 0; i < elements.length; i++) {" |
| 588 " var name = elements[i][0];" | 588 " var name = elements[i][0];" |
| 589 " var label = elements[i][1];" | 589 " var label = elements[i][1];" |
| 590 " AddElement(name, label);" | 590 " AddElement(name, label);" |
| 591 " }" | 591 " }" |
| 592 "};" | 592 "};" |
| 593 "</script>"))); | 593 "</script>"))); |
| 594 | 594 |
| 595 // Dynamically construct the form. | 595 // Dynamically construct the form. |
| 596 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(render_view_host(), L"", | 596 ASSERT_TRUE(content::ExecuteJavaScript(render_view_host(), L"", |
| 597 L"BuildForm();")); | 597 L"BuildForm();")); |
| 598 | 598 |
| 599 // Invoke Autofill. | 599 // Invoke Autofill. |
| 600 TryBasicFormFill(); | 600 TryBasicFormFill(); |
| 601 } | 601 } |
| 602 | 602 |
| 603 // Test that form filling works after reloading the current page. | 603 // Test that form filling works after reloading the current page. |
| 604 // This test brought to you by http://crbug.com/69204 | 604 // This test brought to you by http://crbug.com/69204 |
| 605 #if defined(OS_MACOSX) | 605 #if defined(OS_MACOSX) |
| 606 // Sometimes times out on Mac: http://crbug.com/81451 | 606 // Sometimes times out on Mac: http://crbug.com/81451 |
| 607 // Currently enabled for logging. | 607 // Currently enabled for logging. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 // Pass fake google.translate lib as the translate script. | 692 // Pass fake google.translate lib as the translate script. |
| 693 SimulateURLFetch(true); | 693 SimulateURLFetch(true); |
| 694 | 694 |
| 695 content::WindowedNotificationObserver translation_observer( | 695 content::WindowedNotificationObserver translation_observer( |
| 696 chrome::NOTIFICATION_PAGE_TRANSLATED, | 696 chrome::NOTIFICATION_PAGE_TRANSLATED, |
| 697 content::NotificationService::AllSources()); | 697 content::NotificationService::AllSources()); |
| 698 | 698 |
| 699 // Simulate translation to kick onTranslateElementLoad. | 699 // Simulate translation to kick onTranslateElementLoad. |
| 700 // But right now, the call stucks here. | 700 // But right now, the call stucks here. |
| 701 // Once click the text field, it starts again. | 701 // Once click the text field, it starts again. |
| 702 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 702 ASSERT_TRUE(content::ExecuteJavaScript( |
| 703 render_view_host(), L"", | 703 render_view_host(), L"", |
| 704 L"cr.googleTranslate.onTranslateElementLoad();")); | 704 L"cr.googleTranslate.onTranslateElementLoad();")); |
| 705 | 705 |
| 706 // Simulate the render notifying the translation has been done. | 706 // Simulate the render notifying the translation has been done. |
| 707 translation_observer.Wait(); | 707 translation_observer.Wait(); |
| 708 | 708 |
| 709 TryBasicFormFill(); | 709 TryBasicFormFill(); |
| 710 } | 710 } |
| OLD | NEW |