Chromium Code Reviews| 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) { | |
|
amit
2010/05/26 22:58:42
nice action :)
| |
| 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"); |
|
amit
2010/05/26 22:58:42
Is this the same one as used in other window open
kkania
2013/02/28 21:50:54
It works on XP ie6 and win7 ie8. Perhaps it was Ch
| |
| 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 | |
| 158 mock_.ExpectNavigationInIE(empty_page_url()); | |
| 159 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(empty_page_url()))) | |
| 160 .WillOnce(CloseBrowserMock(&mock_)); | |
| 161 | |
| 162 LaunchIEAndNavigate(kRedirectUrl); | |
| 163 } | |
| 164 | |
| 165 TEST_F(NoInterferenceTest, FLAKY_FollowLink) { | |
| 166 mock_.ExpectNavigationInIE(link_page_url()); | |
| 167 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(link_page_url()))) | |
| 168 .WillOnce(testing::DoAll( | |
| 169 DelaySendMouseClickToIE(&mock_, &loop_, 0, 1, 1, | |
| 170 simulate_input::LEFT), | |
| 171 DelaySendScanCode(&loop_, 500, VK_TAB, simulate_input::NONE), | |
| 172 DelaySendScanCode(&loop_, 1000, VK_RETURN, simulate_input::NONE))); | |
| 173 | |
| 174 mock_.ExpectNavigationInIE(empty_page_url()); | |
| 175 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(empty_page_url()))) | |
| 176 .WillOnce(testing::DoAll( | |
| 177 VerifyAddressBarUrl(&mock_), | |
| 178 CloseBrowserMock(&mock_))); | |
| 179 | |
| 180 LaunchIEAndNavigate(link_page_url()); | |
| 181 } | |
| 182 | |
| 183 TEST_F(NoInterferenceTest, FLAKY_SelectContextMenuOpen) { | |
| 184 mock_.ExpectNavigationInIE(link_page_url()); | |
| 185 // Focus the renderer window by clicking and then tab once to highlight the | |
| 186 // link. | |
| 187 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(link_page_url()))) | |
| 188 .WillOnce(testing::DoAll( | |
| 189 DelaySendMouseClickToIE(&mock_, &loop_, 0, 1, 1, | |
| 190 simulate_input::LEFT), | |
| 191 DelaySendScanCode(&loop_, 500, VK_TAB, simulate_input::NONE), | |
| 192 OpenContextMenu(&loop_, 1000), | |
| 193 SelectItem(&loop_, 1500, 0))); | |
| 194 | |
| 195 mock_.ExpectNavigationInIE(empty_page_url()); | |
| 196 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(empty_page_url()))) | |
| 197 .WillOnce(testing::DoAll( | |
| 198 VerifyAddressBarUrl(&mock_), | |
| 199 CloseBrowserMock(&mock_))); | |
| 200 | |
| 201 LaunchIEAndNavigate(link_page_url()); | |
| 202 } | |
| 203 | |
| 204 TEST_F(NoInterferenceTest, FLAKY_SelectContextMenuOpenInNewWindow) { | |
| 205 ComStackObjectWithUninitialize< | |
| 206 testing::StrictMock<MockWebBrowserEventSink> > new_window_mock; | |
| 207 int open_new_window_index = 2; | |
| 208 if (chrome_frame_test::GetInstalledIEVersion() == IE_6) | |
| 209 open_new_window_index = 1; | |
| 210 | |
| 211 // Focus the renderer window by clicking and then tab once to highlight the | |
| 212 // link. | |
| 213 mock_.ExpectNavigationInIE(link_page_url()); | |
| 214 EXPECT_CALL(mock_, OnIELoad(testing::StrCaseEq(link_page_url()))) | |
| 215 .WillOnce(testing::DoAll( | |
| 216 DelaySendMouseClickToIE(&mock_, &loop_, 0, 1, 1, | |
| 217 simulate_input::LEFT), | |
| 218 DelaySendScanCode(&loop_, 500, VK_TAB, simulate_input::NONE), | |
| 219 OpenContextMenu(&loop_, 1000), | |
| 220 SelectItem(&loop_, 1500, open_new_window_index))); | |
| 221 | |
| 222 mock_.ExpectNewWindowWithIE(empty_page_url(), &new_window_mock); | |
| 223 EXPECT_CALL(new_window_mock, OnIELoad(testing::StrCaseEq(empty_page_url()))) | |
| 224 .WillOnce(testing::DoAll( | |
| 225 VerifyAddressBarUrl(&new_window_mock), | |
| 226 CloseBrowserMock(&new_window_mock))); | |
| 227 EXPECT_CALL(new_window_mock, OnQuit()).WillOnce(CloseBrowserMock(&mock_)); | |
| 228 | |
| 229 LaunchIEAndNavigate(link_page_url()); | |
| 230 } | |
| 231 | |
| 129 } // namespace | 232 } // namespace |
| OLD | NEW |