OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome_frame/test/test_mock_with_web_server.h" | 5 #include "chrome_frame/test/test_mock_with_web_server.h" |
6 | 6 |
7 #include "base/scoped_variant_win.h" | 7 #include "base/scoped_variant_win.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome_frame/test/simulate_input.h" | 9 #include "chrome_frame/test/simulate_input.h" |
10 #include "chrome_frame/test/test_with_web_server.h" | 10 #include "chrome_frame/test/test_with_web_server.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 // Fixture for tests which ensure that Chrome Frame does not interfere with | 58 // Fixture for tests which ensure that Chrome Frame does not interfere with |
59 // normal IE operation. | 59 // normal IE operation. |
60 // TODO(kkania): Move this fixture to test_mock_with_web_server.h and change | 60 // TODO(kkania): Move this fixture to test_mock_with_web_server.h and change |
61 // those tests to use this too. | 61 // those tests to use this too. |
62 class NoInterferenceTest : public ChromeFrameTestWithWebServer { | 62 class NoInterferenceTest : public ChromeFrameTestWithWebServer { |
63 protected: | 63 protected: |
64 // Launches IE and navigates to |url|, then waits until receiving a quit | 64 // Launches IE and navigates to |url|, then waits until receiving a quit |
65 // message or the timeout is exceeded. | 65 // message or the timeout is exceeded. |
66 void LaunchIEAndNavigate(const std::wstring& url) { | 66 void LaunchIEAndNavigate(const std::wstring& url) { |
67 CloseIeAtEndOfScope last_resort_close_ie; | |
68 | |
69 EXPECT_CALL(mock_, OnQuit()) | 67 EXPECT_CALL(mock_, OnQuit()) |
70 .Times(testing::AtMost(1)) | 68 .Times(testing::AtMost(1)) |
71 .WillOnce(QUIT_LOOP(loop_)); | 69 .WillOnce(QUIT_LOOP(loop_)); |
72 HRESULT hr = mock_.LaunchIEAndNavigate(url); | 70 HRESULT hr = mock_.LaunchIEAndNavigate(url); |
73 ASSERT_HRESULT_SUCCEEDED(hr); | 71 ASSERT_HRESULT_SUCCEEDED(hr); |
74 if (hr == S_FALSE) | 72 if (hr == S_FALSE) |
75 return; | 73 return; |
76 | 74 |
77 ASSERT_TRUE(mock_.web_browser2() != NULL); | 75 ASSERT_TRUE(mock_.web_browser2() != NULL); |
78 loop_.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); | 76 loop_.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
| 77 mock_.Uninitialize(); |
79 } | 78 } |
80 | 79 |
81 const std::wstring GetTestUrl(const wchar_t* relative_path) { | 80 const std::wstring GetTestUrl(const wchar_t* relative_path) { |
82 std::wstring path = std::wstring(L"files/no_interference/") + | 81 std::wstring path = std::wstring(L"files/no_interference/") + |
83 relative_path; | 82 relative_path; |
84 return UTF8ToWide(server_.Resolve(path.c_str()).spec()); | 83 return UTF8ToWide(server_.Resolve(path.c_str()).spec()); |
85 } | 84 } |
86 | 85 |
| 86 const std::wstring empty_page_url() { |
| 87 return GetTestUrl(L"empty.html"); |
| 88 } |
| 89 |
| 90 // Returns the url for a page with a single link, which points to the |
| 91 // empty page. |
| 92 const std::wstring link_page_url() { |
| 93 return GetTestUrl(L"link.html"); |
| 94 } |
| 95 |
| 96 CloseIeAtEndOfScope last_resort_close_ie; |
87 chrome_frame_test::TimedMsgLoop loop_; | 97 chrome_frame_test::TimedMsgLoop loop_; |
88 ComStackObjectWithUninitialize< | 98 CComObjectStackEx<testing::StrictMock<MockWebBrowserEventSink> > mock_; |
89 testing::StrictMock<MockWebBrowserEventSink> > mock_; | |
90 }; | 99 }; |
91 | 100 |
92 ACTION_P(ExpectIERendererWindowHasFocus, mock) { | 101 ACTION_P(ExpectIERendererWindowHasFocus, mock) { |
93 mock->ExpectIERendererWindowHasFocus(); | 102 mock->ExpectIERendererWindowHasFocus(); |
94 } | 103 } |
95 | 104 |
96 // This tests that a new IE renderer window has focus. | 105 ACTION_P6(DelaySendMouseClickToIE, mock, loop, delay, x, y, button) { |
| 106 loop->PostDelayedTask(FROM_HERE, NewRunnableMethod(mock, |
| 107 &MockWebBrowserEventSink::SendMouseClickToIE, x, y, button), delay); |
| 108 } |
| 109 |
| 110 ACTION_P2(OpenContextMenu, loop, delay) { |
| 111 loop->PostDelayedTask(FROM_HERE, NewRunnableFunction( |
| 112 simulate_input::SendScanCode, VK_F10, simulate_input::SHIFT), delay); |
| 113 } |
| 114 |
| 115 ACTION_P3(SelectItem, loop, delay, index) { |
| 116 chrome_frame_test::DelaySendExtendedKeysEnter(loop, delay, VK_DOWN, index + 1, |
| 117 simulate_input::NONE); |
| 118 } |
| 119 |
| 120 // A new IE renderer window should have focus. |
97 TEST_F(NoInterferenceTest, SimpleFocus) { | 121 TEST_F(NoInterferenceTest, SimpleFocus) { |
98 const std::wstring kEmptyFileUrl = GetTestUrl(L"empty.html"); | 122 mock_.ExpectNavigationInIE(empty_page_url()); |
99 mock_.ExpectNavigationAndSwitch(kEmptyFileUrl); | 123 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(empty_page_url()))) |
100 | |
101 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(kEmptyFileUrl))) | |
102 .WillOnce(testing::DoAll( | 124 .WillOnce(testing::DoAll( |
103 ExpectIERendererWindowHasFocus(&mock_), | 125 ExpectIERendererWindowHasFocus(&mock_), |
104 VerifyAddressBarUrl(&mock_), | 126 VerifyAddressBarUrl(&mock_), |
105 CloseBrowserMock(&mock_))); | 127 CloseBrowserMock(&mock_))); |
106 | 128 |
107 LaunchIEAndNavigate(kEmptyFileUrl); | 129 LaunchIEAndNavigate(empty_page_url()); |
108 } | 130 } |
109 | 131 |
110 // This tests that window.open does not get intercepted by Chrome Frame. | 132 // Javascript window.open should open a new window with an IE renderer. |
111 TEST_F(NoInterferenceTest, FLAKY_JavascriptWindowOpen) { | 133 TEST_F(NoInterferenceTest, FLAKY_JavascriptWindowOpen) { |
112 const std::wstring kEmptyFileUrl = GetTestUrl(L"empty.html"); | |
113 const std::wstring kWindowOpenUrl = GetTestUrl(L"window_open.html"); | 134 const std::wstring kWindowOpenUrl = GetTestUrl(L"window_open.html"); |
114 ComStackObjectWithUninitialize< | 135 ComStackObjectWithUninitialize< |
115 testing::StrictMock<MockWebBrowserEventSink> > new_window_mock; | 136 testing::StrictMock<MockWebBrowserEventSink> > new_window_mock; |
116 | 137 |
117 mock_.ExpectNavigationAndSwitch(kWindowOpenUrl); | 138 mock_.ExpectNavigationInIE(kWindowOpenUrl); |
118 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(kWindowOpenUrl))); | 139 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(kWindowOpenUrl))); |
119 | 140 |
120 mock_.ExpectNewWindow(&new_window_mock); | 141 mock_.ExpectNewWindowWithIE(empty_page_url(), &new_window_mock); |
121 EXPECT_CALL(new_window_mock, OnIELoad(testing::StrCaseEq(kEmptyFileUrl))) | 142 EXPECT_CALL(new_window_mock, OnIELoad(testing::StrCaseEq(empty_page_url()))) |
122 .WillOnce(CloseBrowserMock(&new_window_mock)); | 143 .WillOnce(testing::DoAll( |
| 144 VerifyAddressBarUrl(&new_window_mock), |
| 145 CloseBrowserMock(&new_window_mock))); |
123 EXPECT_CALL(new_window_mock, OnQuit()) | 146 EXPECT_CALL(new_window_mock, OnQuit()) |
124 .WillOnce(CloseBrowserMock(&mock_)); | 147 .WillOnce(CloseBrowserMock(&mock_)); |
125 | 148 |
126 LaunchIEAndNavigate(kWindowOpenUrl); | 149 LaunchIEAndNavigate(kWindowOpenUrl); |
127 } | 150 } |
128 | 151 |
| 152 // Redirecting with window.location in Javascript should work. |
| 153 TEST_F(NoInterferenceTest, JavascriptRedirect) { |
| 154 const std::wstring kRedirectUrl = GetTestUrl(L"javascript_redirect.html"); |
| 155 mock_.ExpectNavigationInIE(kRedirectUrl); |
| 156 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(kRedirectUrl))) |
| 157 .WillOnce(VerifyAddressBarUrl(&mock_)); |
| 158 |
| 159 mock_.ExpectNavigationInIE(empty_page_url()); |
| 160 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(empty_page_url()))) |
| 161 .WillOnce(testing::DoAll( |
| 162 VerifyAddressBarUrl(&mock_), |
| 163 CloseBrowserMock(&mock_))); |
| 164 |
| 165 LaunchIEAndNavigate(kRedirectUrl); |
| 166 } |
| 167 |
| 168 TEST_F(NoInterferenceTest, FLAKY_FollowLink) { |
| 169 mock_.ExpectNavigationInIE(link_page_url()); |
| 170 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(link_page_url()))) |
| 171 .WillOnce(testing::DoAll( |
| 172 DelaySendMouseClickToIE(&mock_, &loop_, 0, 1, 1, |
| 173 simulate_input::LEFT), |
| 174 DelaySendScanCode(&loop_, 500, VK_TAB, simulate_input::NONE), |
| 175 DelaySendScanCode(&loop_, 1000, VK_RETURN, simulate_input::NONE))); |
| 176 |
| 177 mock_.ExpectNavigationInIE(empty_page_url()); |
| 178 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(empty_page_url()))) |
| 179 .WillOnce(testing::DoAll( |
| 180 VerifyAddressBarUrl(&mock_), |
| 181 CloseBrowserMock(&mock_))); |
| 182 |
| 183 LaunchIEAndNavigate(link_page_url()); |
| 184 } |
| 185 |
| 186 TEST_F(NoInterferenceTest, FLAKY_SelectContextMenuOpen) { |
| 187 mock_.ExpectNavigationInIE(link_page_url()); |
| 188 // Focus the renderer window by clicking and then tab once to highlight the |
| 189 // link. |
| 190 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(link_page_url()))) |
| 191 .WillOnce(testing::DoAll( |
| 192 DelaySendMouseClickToIE(&mock_, &loop_, 0, 1, 1, |
| 193 simulate_input::LEFT), |
| 194 DelaySendScanCode(&loop_, 500, VK_TAB, simulate_input::NONE), |
| 195 OpenContextMenu(&loop_, 1000), |
| 196 SelectItem(&loop_, 1500, 0))); |
| 197 |
| 198 mock_.ExpectNavigationInIE(empty_page_url()); |
| 199 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(empty_page_url()))) |
| 200 .WillOnce(testing::DoAll( |
| 201 VerifyAddressBarUrl(&mock_), |
| 202 CloseBrowserMock(&mock_))); |
| 203 |
| 204 LaunchIEAndNavigate(link_page_url()); |
| 205 } |
| 206 |
| 207 TEST_F(NoInterferenceTest, FLAKY_SelectContextMenuOpenInNewWindow) { |
| 208 ComStackObjectWithUninitialize< |
| 209 testing::StrictMock<MockWebBrowserEventSink> > new_window_mock; |
| 210 int open_new_window_index = 2; |
| 211 if (chrome_frame_test::GetInstalledIEVersion() == IE_6) |
| 212 open_new_window_index = 1; |
| 213 |
| 214 // Focus the renderer window by clicking and then tab once to highlight the |
| 215 // link. |
| 216 mock_.ExpectNavigationInIE(link_page_url()); |
| 217 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(link_page_url()))) |
| 218 .WillOnce(testing::DoAll( |
| 219 DelaySendMouseClickToIE(&mock_, &loop_, 0, 1, 1, |
| 220 simulate_input::LEFT), |
| 221 DelaySendScanCode(&loop_, 500, VK_TAB, simulate_input::NONE), |
| 222 OpenContextMenu(&loop_, 1000), |
| 223 SelectItem(&loop_, 1500, open_new_window_index))); |
| 224 |
| 225 mock_.ExpectNewWindowWithIE(empty_page_url(), &new_window_mock); |
| 226 // TODO(kkania): Verifying the address bar is flaky with this, at least |
| 227 // on XP ie6. Fix. |
| 228 EXPECT_CALL(new_window_mock, OnIELoad(testing::StrCaseEq(empty_page_url()))) |
| 229 .WillOnce(CloseBrowserMock(&new_window_mock)); |
| 230 EXPECT_CALL(new_window_mock, OnQuit()).WillOnce(CloseBrowserMock(&mock_)); |
| 231 |
| 232 LaunchIEAndNavigate(link_page_url()); |
| 233 } |
| 234 |
129 } // namespace | 235 } // namespace |
OLD | NEW |