OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/dom_operation_notification_details.h" | 13 #include "chrome/browser/dom_operation_notification_details.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/common/chrome_notification_types.h" |
15 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/test/in_process_browser_test.h" | 17 #include "chrome/test/in_process_browser_test.h" |
17 #include "chrome/test/ui_test_utils.h" | 18 #include "chrome/test/ui_test_utils.h" |
18 #include "content/browser/renderer_host/render_view_host.h" | 19 #include "content/browser/renderer_host/render_view_host.h" |
19 #include "content/browser/renderer_host/render_widget_host_view.h" | 20 #include "content/browser/renderer_host/render_widget_host_view.h" |
20 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
21 #include "content/browser/tab_contents/tab_contents_view.h" | 22 #include "content/browser/tab_contents/tab_contents_view.h" |
22 #include "content/common/notification_registrar.h" | 23 #include "content/common/notification_registrar.h" |
23 #include "content/common/notification_service.h" | 24 #include "content/common/notification_service.h" |
24 #include "net/test/test_server.h" | 25 #include "net/test/test_server.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 79 |
79 const wchar_t* GetBoolString(bool value) { | 80 const wchar_t* GetBoolString(bool value) { |
80 return value ? L"true" : L"false"; | 81 return value ? L"true" : L"false"; |
81 } | 82 } |
82 | 83 |
83 // A class to help wait for the finish of a key event test. | 84 // A class to help wait for the finish of a key event test. |
84 class TestFinishObserver : public NotificationObserver { | 85 class TestFinishObserver : public NotificationObserver { |
85 public: | 86 public: |
86 explicit TestFinishObserver(RenderViewHost* render_view_host) | 87 explicit TestFinishObserver(RenderViewHost* render_view_host) |
87 : finished_(false), waiting_(false) { | 88 : finished_(false), waiting_(false) { |
88 registrar_.Add(this, NotificationType::DOM_OPERATION_RESPONSE, | 89 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, |
89 Source<RenderViewHost>(render_view_host)); | 90 Source<RenderViewHost>(render_view_host)); |
90 } | 91 } |
91 | 92 |
92 bool WaitForFinish() { | 93 bool WaitForFinish() { |
93 if (!finished_) { | 94 if (!finished_) { |
94 waiting_ = true; | 95 waiting_ = true; |
95 ui_test_utils::RunMessageLoop(); | 96 ui_test_utils::RunMessageLoop(); |
96 waiting_ = false; | 97 waiting_ = false; |
97 } | 98 } |
98 return finished_; | 99 return finished_; |
99 } | 100 } |
100 | 101 |
101 virtual void Observe(NotificationType type, | 102 virtual void Observe(int type, |
102 const NotificationSource& source, | 103 const NotificationSource& source, |
103 const NotificationDetails& details) { | 104 const NotificationDetails& details) { |
104 DCHECK(type == NotificationType::DOM_OPERATION_RESPONSE); | 105 DCHECK(type == chrome::NOTIFICATION_DOM_OPERATION_RESPONSE); |
105 Details<DomOperationNotificationDetails> dom_op_details(details); | 106 Details<DomOperationNotificationDetails> dom_op_details(details); |
106 // We might receive responses for other script execution, but we only | 107 // We might receive responses for other script execution, but we only |
107 // care about the test finished message. | 108 // care about the test finished message. |
108 if (dom_op_details->json() == "\"FINISHED\"") { | 109 if (dom_op_details->json() == "\"FINISHED\"") { |
109 finished_ = true; | 110 finished_ = true; |
110 if (waiting_) | 111 if (waiting_) |
111 MessageLoopForUI::current()->Quit(); | 112 MessageLoopForUI::current()->Quit(); |
112 } | 113 } |
113 } | 114 } |
114 | 115 |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 true, false, false, false, 1, | 668 true, false, false, false, 1, |
668 { "D 91 0 false false false true" } | 669 { "D 91 0 false false false true" } |
669 #else | 670 #else |
670 ui::VKEY_T, true, false, false, false, | 671 ui::VKEY_T, true, false, false, false, |
671 true, false, false, false, 1, | 672 true, false, false, false, 1, |
672 { "D 17 0 true false false false" } | 673 { "D 17 0 true false false false" } |
673 #endif | 674 #endif |
674 }; | 675 }; |
675 | 676 |
676 ui_test_utils::WindowedNotificationObserver wait_for_new_tab( | 677 ui_test_utils::WindowedNotificationObserver wait_for_new_tab( |
677 NotificationType::TAB_PARENTED, | 678 content::NOTIFICATION_TAB_PARENTED, |
678 NotificationService::AllSources()); | 679 NotificationService::AllSources()); |
679 | 680 |
680 // Press Ctrl/Cmd+T, which will open a new tab. It cannot be suppressed. | 681 // Press Ctrl/Cmd+T, which will open a new tab. It cannot be suppressed. |
681 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlOrCmdT)); | 682 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(0, kTestCtrlOrCmdT)); |
682 | 683 |
683 ASSERT_NO_FATAL_FAILURE( | 684 ASSERT_NO_FATAL_FAILURE( |
684 wait_for_new_tab.WaitFor(Source<TabContentsWrapper>( | 685 wait_for_new_tab.WaitFor(Source<TabContentsWrapper>( |
685 browser()->GetTabContentsWrapperAt(1)))); | 686 browser()->GetTabContentsWrapperAt(1)))); |
686 | 687 |
687 int result_length; | 688 int result_length; |
688 ASSERT_NO_FATAL_FAILURE(GetResultLength(0, &result_length)); | 689 ASSERT_NO_FATAL_FAILURE(GetResultLength(0, &result_length)); |
689 EXPECT_EQ(1, result_length); | 690 EXPECT_EQ(1, result_length); |
690 | 691 |
691 EXPECT_EQ(2, browser()->tab_count()); | 692 EXPECT_EQ(2, browser()->tab_count()); |
692 ASSERT_EQ(1, browser()->active_index()); | 693 ASSERT_EQ(1, browser()->active_index()); |
693 | 694 |
694 // Because of issue http://crbug.com/65375, switching back to the first tab | 695 // Because of issue http://crbug.com/65375, switching back to the first tab |
695 // may cause the focus to be grabbed by omnibox. So instead, we load our | 696 // may cause the focus to be grabbed by omnibox. So instead, we load our |
696 // testing page in the newly created tab and try Cmd-W here. | 697 // testing page in the newly created tab and try Cmd-W here. |
697 ui_test_utils::NavigateToURL(browser(), url); | 698 ui_test_utils::NavigateToURL(browser(), url); |
698 | 699 |
699 // Make sure the focus is in the testing page. | 700 // Make sure the focus is in the testing page. |
700 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); | 701 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); |
701 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 702 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
702 | 703 |
703 // Reserved accelerators can't be suppressed. | 704 // Reserved accelerators can't be suppressed. |
704 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(1, true)); | 705 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(1, true)); |
705 | 706 |
706 ui_test_utils::WindowedNotificationObserver wait_for_tab_closed( | 707 ui_test_utils::WindowedNotificationObserver wait_for_tab_closed( |
707 NotificationType::TAB_CLOSED, Source<NavigationController>( | 708 content::NOTIFICATION_TAB_CLOSED, Source<NavigationController>( |
708 &browser()->GetTabContentsAt(1)->controller())); | 709 &browser()->GetTabContentsAt(1)->controller())); |
709 | 710 |
710 // Press Ctrl/Cmd+W, which will close the tab. | 711 // Press Ctrl/Cmd+W, which will close the tab. |
711 #if defined(OS_MACOSX) | 712 #if defined(OS_MACOSX) |
712 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 713 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
713 browser(), ui::VKEY_W, false, false, false, true)); | 714 browser(), ui::VKEY_W, false, false, false, true)); |
714 #else | 715 #else |
715 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 716 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
716 browser(), ui::VKEY_W, true, false, false, false)); | 717 browser(), ui::VKEY_W, true, false, false, false)); |
717 #endif | 718 #endif |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress)); | 850 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress)); |
850 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 851 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
851 | 852 |
852 // Ctrl+Alt should have no effect. | 853 // Ctrl+Alt should have no effect. |
853 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey)); | 854 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey)); |
854 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 855 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
855 } | 856 } |
856 #endif | 857 #endif |
857 | 858 |
858 } // namespace | 859 } // namespace |
OLD | NEW |