| OLD | NEW |
| (Empty) |
| 1 // Copyright 2007-2010 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 // This unit test is driving the UI through its states so that we can | |
| 17 // visually inspect all the controls are there in their right state and | |
| 18 // position. To go from state to state, simply close the window on the screen. | |
| 19 // | |
| 20 // The unit test is useful for debugging UI states so different tests are | |
| 21 // enabled/disabled at compile time, depending what needs to be tested. | |
| 22 | |
| 23 #include <windows.h> | |
| 24 #include "omaha/base/utils.h" | |
| 25 #include "omaha/client/install_progress_observer.h" | |
| 26 #include "omaha/testing/unit_test.h" | |
| 27 #include "omaha/ui/ui.h" | |
| 28 #include "omaha/ui/progress_wnd.h" | |
| 29 | |
| 30 namespace omaha { | |
| 31 | |
| 32 class UITest : public testing::Test, | |
| 33 public ProgressWndEvents, | |
| 34 public WaitCallbackInterface { | |
| 35 protected: | |
| 36 UITest() : progress_wnd_(&progress_wnd_message_loop_, NULL) { | |
| 37 } | |
| 38 | |
| 39 static void SetUpTestCase() { | |
| 40 message_loop_.set_message_handler(&message_handler_); | |
| 41 reset(ev_, ::CreateEvent(NULL, false, false, NULL)); | |
| 42 } | |
| 43 | |
| 44 virtual void SetUp() { | |
| 45 ASSERT_TRUE(::ResetEvent(get(ev_))); | |
| 46 ASSERT_TRUE(message_loop_.RegisterWaitForSingleObject(get(ev_), this)); | |
| 47 /* | |
| 48 progress_wnd_.SetEventSink(this); | |
| 49 progress_wnd_.set_bundle_name(_T("FooBar")); | |
| 50 EXPECT_SUCCEEDED(progress_wnd_.Initialize()); | |
| 51 EXPECT_TRUE(progress_wnd_.CenterWindow(NULL)); | |
| 52 progress_wnd_.SetVisible(true); | |
| 53 */ | |
| 54 } | |
| 55 | |
| 56 virtual void TearDown() { | |
| 57 message_loop_.UnregisterWait(get(ev_)); | |
| 58 } | |
| 59 | |
| 60 // | |
| 61 // ProgressWndEvents | |
| 62 // | |
| 63 virtual void DoPause() { | |
| 64 } | |
| 65 | |
| 66 virtual void DoResume() { | |
| 67 } | |
| 68 | |
| 69 virtual void DoClose() { | |
| 70 ASSERT_TRUE(::SetEvent(get(ev_))); | |
| 71 } | |
| 72 | |
| 73 virtual void DoExit() { | |
| 74 ASSERT_TRUE(::SetEvent(get(ev_))); | |
| 75 } | |
| 76 | |
| 77 virtual void DoCancel() { | |
| 78 ASSERT_TRUE(::SetEvent(get(ev_))); | |
| 79 } | |
| 80 | |
| 81 virtual bool DoRestartBrowser(bool restart_all_browsers, | |
| 82 const std::vector<CString>& urls) { | |
| 83 UNREFERENCED_PARAMETER(restart_all_browsers); | |
| 84 UNREFERENCED_PARAMETER(urls); | |
| 85 | |
| 86 EXPECT_TRUE(::SetEvent(get(ev_))); | |
| 87 return true; | |
| 88 } | |
| 89 | |
| 90 virtual bool DoReboot() { | |
| 91 EXPECT_TRUE(::SetEvent(get(ev_))); | |
| 92 return true; | |
| 93 } | |
| 94 | |
| 95 virtual bool DoLaunchBrowser(const CString&) { | |
| 96 return true; | |
| 97 } | |
| 98 | |
| 99 // | |
| 100 // WaitCallbackInterface | |
| 101 // | |
| 102 virtual bool HandleSignaled(HANDLE) { | |
| 103 // Makes the message pump stop. | |
| 104 return false; | |
| 105 } | |
| 106 | |
| 107 void FormatWindowTitle(const TCHAR* text) { | |
| 108 CString title; | |
| 109 progress_wnd_.GetWindowText(CStrBuf(title, 256), 256); | |
| 110 CString new_title; | |
| 111 new_title.Format(_T("%s - %s"), title, text); | |
| 112 progress_wnd_.SetWindowText(new_title); | |
| 113 } | |
| 114 | |
| 115 CompletionCodes GetBundleOverallCompletionCode( | |
| 116 const ObserverCompletionInfo& observer_info) { | |
| 117 return progress_wnd_.GetBundleOverallCompletionCode(observer_info); | |
| 118 } | |
| 119 | |
| 120 static BasicMessageHandler message_handler_; | |
| 121 static MessageLoopWithWait message_loop_; | |
| 122 ProgressWnd progress_wnd_; | |
| 123 CMessageLoop progress_wnd_message_loop_; | |
| 124 static scoped_event ev_; | |
| 125 }; | |
| 126 | |
| 127 BasicMessageHandler UITest::message_handler_; | |
| 128 MessageLoopWithWait UITest::message_loop_; | |
| 129 scoped_event UITest::ev_; | |
| 130 | |
| 131 const CompletionCodes kCompletionCodesPriority[] = { | |
| 132 COMPLETION_CODE_EXIT_SILENTLY, | |
| 133 COMPLETION_CODE_EXIT_SILENTLY_ON_LAUNCH_COMMAND, | |
| 134 COMPLETION_CODE_SUCCESS, | |
| 135 COMPLETION_CODE_LAUNCH_COMMAND, | |
| 136 COMPLETION_CODE_RESTART_BROWSER_NOTICE_ONLY, | |
| 137 COMPLETION_CODE_RESTART_ALL_BROWSERS_NOTICE_ONLY, | |
| 138 COMPLETION_CODE_RESTART_BROWSER, | |
| 139 COMPLETION_CODE_RESTART_ALL_BROWSERS, | |
| 140 COMPLETION_CODE_REBOOT_NOTICE_ONLY, | |
| 141 COMPLETION_CODE_REBOOT, | |
| 142 COMPLETION_CODE_ERROR, | |
| 143 }; | |
| 144 | |
| 145 TEST_F(UITest, GetBundleOverallCompletionCode_BundleFailed) { | |
| 146 ObserverCompletionInfo observer_info(COMPLETION_CODE_ERROR); | |
| 147 AppCompletionInfo app_info; | |
| 148 | |
| 149 for (int i = 0; i < arraysize(kCompletionCodesPriority); ++i) { | |
| 150 app_info.completion_code = kCompletionCodesPriority[i]; | |
| 151 observer_info.apps_info.push_back(app_info); | |
| 152 } | |
| 153 | |
| 154 EXPECT_EQ(COMPLETION_CODE_ERROR, | |
| 155 GetBundleOverallCompletionCode(observer_info)); | |
| 156 } | |
| 157 | |
| 158 TEST_F(UITest, GetBundleOverallCompletionCode_BundleSucceeded) { | |
| 159 for (int i = 0; i < arraysize(kCompletionCodesPriority); ++i) { | |
| 160 ObserverCompletionInfo observer_info(COMPLETION_CODE_SUCCESS); | |
| 161 AppCompletionInfo app_info; | |
| 162 | |
| 163 for (int j = 0; j <= i; ++j) { | |
| 164 app_info.completion_code = kCompletionCodesPriority[i]; | |
| 165 observer_info.apps_info.push_back(app_info); | |
| 166 } | |
| 167 | |
| 168 EXPECT_EQ(kCompletionCodesPriority[i], | |
| 169 GetBundleOverallCompletionCode(observer_info)); | |
| 170 } | |
| 171 } | |
| 172 | |
| 173 /* | |
| 174 TEST_F(UITest, Initialize) { | |
| 175 FormatWindowTitle(_T("Initialize")); | |
| 176 message_loop_.Process(); | |
| 177 } | |
| 178 | |
| 179 TEST_F(UITest, OnWaitingToDownload) { | |
| 180 FormatWindowTitle(_T("Waiting to download")); | |
| 181 progress_wnd_.OnWaitingToDownload(); | |
| 182 message_loop_.Process(); | |
| 183 } | |
| 184 | |
| 185 TEST_F(UITest, OnDownloading1) { | |
| 186 FormatWindowTitle(_T("Downloading")); | |
| 187 progress_wnd_.OnDownloading(10000, 0); | |
| 188 message_loop_.Process(); | |
| 189 } | |
| 190 | |
| 191 TEST_F(UITest, OnDownloading2) { | |
| 192 FormatWindowTitle(_T("Downloading")); | |
| 193 progress_wnd_.OnDownloading(5000, 50); | |
| 194 message_loop_.Process(); | |
| 195 } | |
| 196 | |
| 197 TEST_F(UITest, OnDownloading3) { | |
| 198 FormatWindowTitle(_T("Downloading")); | |
| 199 progress_wnd_.OnDownloading(0, 100); | |
| 200 message_loop_.Process(); | |
| 201 } | |
| 202 | |
| 203 TEST_F(UITest, OnWaitingToInstall) { | |
| 204 FormatWindowTitle(_T("Waiting to install")); | |
| 205 progress_wnd_.OnWaitingToInstall(); | |
| 206 message_loop_.Process(); | |
| 207 } | |
| 208 | |
| 209 TEST_F(UITest, OnInstall) { | |
| 210 FormatWindowTitle(_T("Installing")); | |
| 211 progress_wnd_.OnInstalling(); | |
| 212 message_loop_.Process(); | |
| 213 } | |
| 214 | |
| 215 TEST_F(UITest, OnPause) { | |
| 216 FormatWindowTitle(_T("Paused")); | |
| 217 progress_wnd_.OnPause(); | |
| 218 message_loop_.Process(); | |
| 219 } | |
| 220 | |
| 221 TEST_F(UITest, OnCompleteSuccess) { | |
| 222 FormatWindowTitle(_T("Complete success")); | |
| 223 progress_wnd_.OnComplete( | |
| 224 COMPLETION_CODE_SUCCESS, | |
| 225 _T("Thanks for installing Gears. For more information on using ") | |
| 226 _T("Gears visit the ") | |
| 227 _T("<a=http://www.google.com/gears/>Gears</a> web site."), | |
| 228 0); | |
| 229 message_loop_.Process(); | |
| 230 } | |
| 231 | |
| 232 TEST_F(UITest, OnCompleteError) { | |
| 233 FormatWindowTitle(_T("Complete error")); | |
| 234 progress_wnd_.OnComplete( | |
| 235 COMPLETION_CODE_ERROR, | |
| 236 _T("An error occured while installing Gears: an existing copy of ") | |
| 237 _T("Gears is currently running. Please exit the software and ") | |
| 238 _T("retry installation. For more information visit the ") | |
| 239 _T("<a=http://www.google.com/gears/>Gears</a> web site."), | |
| 240 11); | |
| 241 message_loop_.Process(); | |
| 242 } | |
| 243 | |
| 244 TEST_F(UITest, OnCompleteRestartAllBrowsers) { | |
| 245 FormatWindowTitle(_T("Restart browsers")); | |
| 246 progress_wnd_.OnComplete(COMPLETION_CODE_RESTART_ALL_BROWSERS, NULL, 0); | |
| 247 message_loop_.Process(); | |
| 248 } | |
| 249 | |
| 250 TEST_F(UITest, OnCompleteReboot) { | |
| 251 FormatWindowTitle(_T("Reboot")); | |
| 252 progress_wnd_.OnComplete(COMPLETION_CODE_REBOOT, NULL, 0); | |
| 253 message_loop_.Process(); | |
| 254 } | |
| 255 | |
| 256 TEST_F(UITest, OnCompleteRestartBrowser) { | |
| 257 FormatWindowTitle(_T("Restart browser")); | |
| 258 progress_wnd_.OnComplete(COMPLETION_CODE_RESTART_BROWSER, NULL, 0); | |
| 259 message_loop_.Process(); | |
| 260 } | |
| 261 | |
| 262 TEST_F(UITest, OnCompleteRestartAllBrowsersNoticeOnly) { | |
| 263 FormatWindowTitle(_T("Restart browsers")); | |
| 264 progress_wnd_.OnComplete(COMPLETION_CODE_RESTART_ALL_BROWSERS_NOTICE_ONLY, | |
| 265 NULL, | |
| 266 0); | |
| 267 message_loop_.Process(); | |
| 268 } | |
| 269 | |
| 270 TEST_F(UITest, OnCompleteRebootNoticeOnly) { | |
| 271 FormatWindowTitle(_T("Reboot")); | |
| 272 progress_wnd_.OnComplete(COMPLETION_CODE_REBOOT_NOTICE_ONLY, NULL, 0); | |
| 273 message_loop_.Process(); | |
| 274 } | |
| 275 | |
| 276 TEST_F(UITest, OnCompleteRestartBrowserNoticeOnly) { | |
| 277 FormatWindowTitle(_T("Restart browser")); | |
| 278 progress_wnd_.OnComplete(COMPLETION_CODE_RESTART_BROWSER_NOTICE_ONLY, | |
| 279 NULL, | |
| 280 0); | |
| 281 message_loop_.Process(); | |
| 282 } | |
| 283 | |
| 284 // Test the OnComplete can be called multiple times. | |
| 285 TEST_F(UITest, OnMultipleCompletes) { | |
| 286 FormatWindowTitle(_T("Complete success")); | |
| 287 progress_wnd_.OnComplete( | |
| 288 COMPLETION_CODE_SUCCESS, | |
| 289 _T("Thanks for installing Gears. For more information on using ") | |
| 290 _T("Gears visit the ") | |
| 291 _T("<a=http://www.google.com/gears/>Gears</a> web site."), | |
| 292 0); | |
| 293 | |
| 294 FormatWindowTitle(_T("Complete error")); | |
| 295 progress_wnd_.OnComplete( | |
| 296 COMPLETION_CODE_ERROR, | |
| 297 _T("An error occured while installing Gears: an existing copy of ") | |
| 298 _T("Gears is currently running. Please exit the software and ") | |
| 299 _T("retry installation. For more information visit the ") | |
| 300 _T("<a=http://www.google.com/gears/>Gears</a> web site."), | |
| 301 0); | |
| 302 | |
| 303 progress_wnd_.OnComplete( | |
| 304 COMPLETION_CODE_ERROR, | |
| 305 _T("An error occured while installing Gears: an existing copy of ") | |
| 306 _T("Gears is currently running. Please exit the software and ") | |
| 307 _T("retry installation. For more information visit the ") | |
| 308 _T("<a=http://www.google.com/gears/>Gears</a> web site."), | |
| 309 0); | |
| 310 | |
| 311 FormatWindowTitle(_T("Restart browsers")); | |
| 312 progress_wnd_.OnComplete(COMPLETION_CODE_RESTART_ALL_BROWSERS, NULL, 0); | |
| 313 message_loop_.Process(); | |
| 314 } | |
| 315 */ | |
| 316 | |
| 317 } // namespace omaha | |
| 318 | |
| OLD | NEW |