| 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 <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 193 } |
| 194 | 194 |
| 195 void SendKeySequence(const wchar_t* keys) { | 195 void SendKeySequence(const wchar_t* keys) { |
| 196 for (; *keys; ++keys) | 196 for (; *keys; ++keys) |
| 197 ASSERT_NO_FATAL_FAILURE(SendKey(static_cast<ui::KeyboardCode>(*keys), 0)); | 197 ASSERT_NO_FATAL_FAILURE(SendKey(static_cast<ui::KeyboardCode>(*keys), 0)); |
| 198 } | 198 } |
| 199 | 199 |
| 200 bool SendKeyAndWait(const Browser* browser, | 200 bool SendKeyAndWait(const Browser* browser, |
| 201 ui::KeyboardCode key, | 201 ui::KeyboardCode key, |
| 202 int modifiers, | 202 int modifiers, |
| 203 NotificationType type, | 203 int type, |
| 204 const NotificationSource& source) WARN_UNUSED_RESULT { | 204 const NotificationSource& source) WARN_UNUSED_RESULT { |
| 205 return ui_test_utils::SendKeyPressAndWait( | 205 return ui_test_utils::SendKeyPressAndWait( |
| 206 browser, key, | 206 browser, key, |
| 207 (modifiers & ui::EF_CONTROL_DOWN) != 0, | 207 (modifiers & ui::EF_CONTROL_DOWN) != 0, |
| 208 (modifiers & ui::EF_SHIFT_DOWN) != 0, | 208 (modifiers & ui::EF_SHIFT_DOWN) != 0, |
| 209 (modifiers & ui::EF_ALT_DOWN) != 0, | 209 (modifiers & ui::EF_ALT_DOWN) != 0, |
| 210 (modifiers & ui::EF_COMMAND_DOWN) != 0, | 210 (modifiers & ui::EF_COMMAND_DOWN) != 0, |
| 211 type, source); | 211 type, source); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void WaitForTabOpenOrCloseForBrowser(const Browser* browser, | 214 void WaitForTabOpenOrCloseForBrowser(const Browser* browser, |
| 215 int expected_tab_count) { | 215 int expected_tab_count) { |
| 216 int tab_count = browser->tab_count(); | 216 int tab_count = browser->tab_count(); |
| 217 if (tab_count == expected_tab_count) | 217 if (tab_count == expected_tab_count) |
| 218 return; | 218 return; |
| 219 | 219 |
| 220 NotificationRegistrar registrar; | 220 NotificationRegistrar registrar; |
| 221 registrar.Add(this, | 221 registrar.Add(this, |
| 222 (tab_count < expected_tab_count ? | 222 (tab_count < expected_tab_count ? |
| 223 NotificationType::TAB_PARENTED : | 223 chrome::TAB_PARENTED : |
| 224 NotificationType::TAB_CLOSED), | 224 chrome::TAB_CLOSED), |
| 225 NotificationService::AllSources()); | 225 NotificationService::AllSources()); |
| 226 | 226 |
| 227 while (!HasFailure() && browser->tab_count() != expected_tab_count) | 227 while (!HasFailure() && browser->tab_count() != expected_tab_count) |
| 228 ui_test_utils::RunMessageLoop(); | 228 ui_test_utils::RunMessageLoop(); |
| 229 | 229 |
| 230 ASSERT_EQ(expected_tab_count, browser->tab_count()); | 230 ASSERT_EQ(expected_tab_count, browser->tab_count()); |
| 231 } | 231 } |
| 232 | 232 |
| 233 void WaitForTabOpenOrClose(int expected_tab_count) { | 233 void WaitForTabOpenOrClose(int expected_tab_count) { |
| 234 WaitForTabOpenOrCloseForBrowser(browser(), expected_tab_count); | 234 WaitForTabOpenOrCloseForBrowser(browser(), expected_tab_count); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void WaitForAutocompleteControllerDone() { | 237 void WaitForAutocompleteControllerDone() { |
| 238 OmniboxView* omnibox_view = NULL; | 238 OmniboxView* omnibox_view = NULL; |
| 239 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 239 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
| 240 | 240 |
| 241 AutocompleteController* controller = | 241 AutocompleteController* controller = |
| 242 omnibox_view->model()->popup_model()->autocomplete_controller(); | 242 omnibox_view->model()->popup_model()->autocomplete_controller(); |
| 243 ASSERT_TRUE(controller); | 243 ASSERT_TRUE(controller); |
| 244 | 244 |
| 245 if (controller->done()) | 245 if (controller->done()) |
| 246 return; | 246 return; |
| 247 | 247 |
| 248 NotificationRegistrar registrar; | 248 NotificationRegistrar registrar; |
| 249 registrar.Add(this, | 249 registrar.Add(this, |
| 250 NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_READY, | 250 chrome::AUTOCOMPLETE_CONTROLLER_RESULT_READY, |
| 251 Source<AutocompleteController>(controller)); | 251 Source<AutocompleteController>(controller)); |
| 252 | 252 |
| 253 while (!HasFailure() && !controller->done()) | 253 while (!HasFailure() && !controller->done()) |
| 254 ui_test_utils::RunMessageLoop(); | 254 ui_test_utils::RunMessageLoop(); |
| 255 | 255 |
| 256 ASSERT_TRUE(controller->done()); | 256 ASSERT_TRUE(controller->done()); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void SetupSearchEngine() { | 259 void SetupSearchEngine() { |
| 260 TemplateURLService* model = | 260 TemplateURLService* model = |
| 261 TemplateURLServiceFactory::GetForProfile(browser()->profile()); | 261 TemplateURLServiceFactory::GetForProfile(browser()->profile()); |
| 262 ASSERT_TRUE(model); | 262 ASSERT_TRUE(model); |
| 263 | 263 |
| 264 if (!model->loaded()) { | 264 if (!model->loaded()) { |
| 265 NotificationRegistrar registrar; | 265 NotificationRegistrar registrar; |
| 266 registrar.Add(this, NotificationType::TEMPLATE_URL_SERVICE_LOADED, | 266 registrar.Add(this, chrome::TEMPLATE_URL_SERVICE_LOADED, |
| 267 Source<TemplateURLService>(model)); | 267 Source<TemplateURLService>(model)); |
| 268 model->Load(); | 268 model->Load(); |
| 269 ui_test_utils::RunMessageLoop(); | 269 ui_test_utils::RunMessageLoop(); |
| 270 } | 270 } |
| 271 | 271 |
| 272 ASSERT_TRUE(model->loaded()); | 272 ASSERT_TRUE(model->loaded()); |
| 273 // Remove built-in template urls, like google.com, bing.com etc., as they | 273 // Remove built-in template urls, like google.com, bing.com etc., as they |
| 274 // may appear as autocomplete suggests and interfere with our tests. | 274 // may appear as autocomplete suggests and interfere with our tests. |
| 275 model->SetDefaultSearchProvider(NULL); | 275 model->SetDefaultSearchProvider(NULL); |
| 276 TemplateURLService::TemplateURLVector builtins = model->GetTemplateURLs(); | 276 TemplateURLService::TemplateURLVector builtins = model->GetTemplateURLs(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 288 } | 288 } |
| 289 | 289 |
| 290 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) { | 290 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) { |
| 291 Profile* profile = browser()->profile(); | 291 Profile* profile = browser()->profile(); |
| 292 HistoryService* history_service = | 292 HistoryService* history_service = |
| 293 profile->GetHistoryService(Profile::EXPLICIT_ACCESS); | 293 profile->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 294 ASSERT_TRUE(history_service); | 294 ASSERT_TRUE(history_service); |
| 295 | 295 |
| 296 if (!history_service->BackendLoaded()) { | 296 if (!history_service->BackendLoaded()) { |
| 297 NotificationRegistrar registrar; | 297 NotificationRegistrar registrar; |
| 298 registrar.Add(this, NotificationType::HISTORY_LOADED, | 298 registrar.Add(this, chrome::HISTORY_LOADED, |
| 299 Source<Profile>(profile)); | 299 Source<Profile>(profile)); |
| 300 ui_test_utils::RunMessageLoop(); | 300 ui_test_utils::RunMessageLoop(); |
| 301 } | 301 } |
| 302 | 302 |
| 303 BookmarkModel* bookmark_model = profile->GetBookmarkModel(); | 303 BookmarkModel* bookmark_model = profile->GetBookmarkModel(); |
| 304 ASSERT_TRUE(bookmark_model); | 304 ASSERT_TRUE(bookmark_model); |
| 305 | 305 |
| 306 if (!bookmark_model->IsLoaded()) { | 306 if (!bookmark_model->IsLoaded()) { |
| 307 NotificationRegistrar registrar; | 307 NotificationRegistrar registrar; |
| 308 registrar.Add(this, NotificationType::BOOKMARK_MODEL_LOADED, | 308 registrar.Add(this, chrome::BOOKMARK_MODEL_LOADED, |
| 309 Source<Profile>(profile)); | 309 Source<Profile>(profile)); |
| 310 ui_test_utils::RunMessageLoop(); | 310 ui_test_utils::RunMessageLoop(); |
| 311 } | 311 } |
| 312 | 312 |
| 313 GURL url(entry.url); | 313 GURL url(entry.url); |
| 314 // Add everything in order of time. We don't want to have a time that | 314 // Add everything in order of time. We don't want to have a time that |
| 315 // is "right now" or it will nondeterministically appear in the results. | 315 // is "right now" or it will nondeterministically appear in the results. |
| 316 history_service->AddPageWithDetails(url, UTF8ToUTF16(entry.title), | 316 history_service->AddPageWithDetails(url, UTF8ToUTF16(entry.title), |
| 317 entry.visit_count, | 317 entry.visit_count, |
| 318 entry.typed_count, time, false, | 318 entry.typed_count, time, false, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 337 for (size_t i = 0; i < arraysize(kBlockedHostnames); ++i) | 337 for (size_t i = 0; i < arraysize(kBlockedHostnames); ++i) |
| 338 host_resolver()->AddSimulatedFailure(kBlockedHostnames[i]); | 338 host_resolver()->AddSimulatedFailure(kBlockedHostnames[i]); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void SetupComponents() { | 341 void SetupComponents() { |
| 342 ASSERT_NO_FATAL_FAILURE(SetupHostResolver()); | 342 ASSERT_NO_FATAL_FAILURE(SetupHostResolver()); |
| 343 ASSERT_NO_FATAL_FAILURE(SetupSearchEngine()); | 343 ASSERT_NO_FATAL_FAILURE(SetupSearchEngine()); |
| 344 ASSERT_NO_FATAL_FAILURE(SetupHistory()); | 344 ASSERT_NO_FATAL_FAILURE(SetupHistory()); |
| 345 } | 345 } |
| 346 | 346 |
| 347 virtual void Observe(NotificationType type, | 347 virtual void Observe(int type, |
| 348 const NotificationSource& source, | 348 const NotificationSource& source, |
| 349 const NotificationDetails& details) { | 349 const NotificationDetails& details) { |
| 350 switch (type.value) { | 350 switch (type) { |
| 351 case NotificationType::TAB_PARENTED: | 351 case chrome::TAB_PARENTED: |
| 352 case NotificationType::TAB_CLOSED: | 352 case chrome::TAB_CLOSED: |
| 353 case NotificationType::TEMPLATE_URL_SERVICE_LOADED: | 353 case chrome::TEMPLATE_URL_SERVICE_LOADED: |
| 354 case NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_READY: | 354 case chrome::AUTOCOMPLETE_CONTROLLER_RESULT_READY: |
| 355 case NotificationType::HISTORY_LOADED: | 355 case chrome::HISTORY_LOADED: |
| 356 case NotificationType::BOOKMARK_MODEL_LOADED: | 356 case chrome::BOOKMARK_MODEL_LOADED: |
| 357 break; | 357 break; |
| 358 default: | 358 default: |
| 359 FAIL() << "Unexpected notification type"; | 359 FAIL() << "Unexpected notification type"; |
| 360 } | 360 } |
| 361 MessageLoopForUI::current()->Quit(); | 361 MessageLoopForUI::current()->Quit(); |
| 362 } | 362 } |
| 363 | 363 |
| 364 void BrowserAcceleratorsTest() { | 364 void BrowserAcceleratorsTest() { |
| 365 OmniboxView* omnibox_view = NULL; | 365 OmniboxView* omnibox_view = NULL; |
| 366 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 366 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN)); | 409 SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN)); |
| 410 #endif | 410 #endif |
| 411 EXPECT_FALSE(omnibox_view->IsSelectAll()); | 411 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
| 412 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_X, kCtrlOrCmdMask)); | 412 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_X, kCtrlOrCmdMask)); |
| 413 EXPECT_EQ(ASCIIToUTF16("Hello "), omnibox_view->GetText()); | 413 EXPECT_EQ(ASCIIToUTF16("Hello "), omnibox_view->GetText()); |
| 414 | 414 |
| 415 #if !defined(OS_CHROMEOS) && !defined(OS_MACOSX) | 415 #if !defined(OS_CHROMEOS) && !defined(OS_MACOSX) |
| 416 // Try alt-f4 to close the browser. | 416 // Try alt-f4 to close the browser. |
| 417 ASSERT_TRUE(SendKeyAndWait( | 417 ASSERT_TRUE(SendKeyAndWait( |
| 418 browser(), ui::VKEY_F4, ui::EF_ALT_DOWN, | 418 browser(), ui::VKEY_F4, ui::EF_ALT_DOWN, |
| 419 NotificationType::BROWSER_CLOSED, Source<Browser>(browser()))); | 419 chrome::NOTIFICATION_BROWSER_CLOSED, Source<Browser>(browser()))); |
| 420 #endif | 420 #endif |
| 421 } | 421 } |
| 422 | 422 |
| 423 void PopupAcceleratorsTest() { | 423 void PopupAcceleratorsTest() { |
| 424 // Create a popup. | 424 // Create a popup. |
| 425 Browser* popup = CreateBrowserForPopup(browser()->profile()); | 425 Browser* popup = CreateBrowserForPopup(browser()->profile()); |
| 426 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(popup)); | 426 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(popup)); |
| 427 OmniboxView* omnibox_view = NULL; | 427 OmniboxView* omnibox_view = NULL; |
| 428 ASSERT_NO_FATAL_FAILURE( | 428 ASSERT_NO_FATAL_FAILURE( |
| 429 GetOmniboxViewForBrowser(popup, &omnibox_view)); | 429 GetOmniboxViewForBrowser(popup, &omnibox_view)); |
| 430 popup->FocusLocationBar(); | 430 popup->FocusLocationBar(); |
| 431 EXPECT_TRUE(omnibox_view->IsSelectAll()); | 431 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
| 432 | 432 |
| 433 #if !defined(OS_MACOSX) | 433 #if !defined(OS_MACOSX) |
| 434 // Try ctrl-w to close the popup. | 434 // Try ctrl-w to close the popup. |
| 435 // This piece of code doesn't work on Mac, because the Browser object won't | 435 // This piece of code doesn't work on Mac, because the Browser object won't |
| 436 // be destroyed before finishing the current message loop iteration, thus | 436 // be destroyed before finishing the current message loop iteration, thus |
| 437 // No BROWSER_CLOSED notification will be sent. | 437 // No BROWSER_CLOSED notification will be sent. |
| 438 ASSERT_TRUE(SendKeyAndWait( | 438 ASSERT_TRUE(SendKeyAndWait( |
| 439 popup, ui::VKEY_W, ui::EF_CONTROL_DOWN, | 439 popup, ui::VKEY_W, ui::EF_CONTROL_DOWN, |
| 440 NotificationType::BROWSER_CLOSED, Source<Browser>(popup))); | 440 chrome::NOTIFICATION_BROWSER_CLOSED, Source<Browser>(popup))); |
| 441 | 441 |
| 442 // Create another popup. | 442 // Create another popup. |
| 443 popup = CreateBrowserForPopup(browser()->profile()); | 443 popup = CreateBrowserForPopup(browser()->profile()); |
| 444 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(popup)); | 444 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(popup)); |
| 445 ASSERT_NO_FATAL_FAILURE( | 445 ASSERT_NO_FATAL_FAILURE( |
| 446 GetOmniboxViewForBrowser(popup, &omnibox_view)); | 446 GetOmniboxViewForBrowser(popup, &omnibox_view)); |
| 447 #endif | 447 #endif |
| 448 | 448 |
| 449 // Set the edit text to "Hello world". | 449 // Set the edit text to "Hello world". |
| 450 omnibox_view->SetUserText(ASCIIToUTF16("Hello world")); | 450 omnibox_view->SetUserText(ASCIIToUTF16("Hello world")); |
| 451 popup->FocusLocationBar(); | 451 popup->FocusLocationBar(); |
| 452 EXPECT_TRUE(omnibox_view->IsSelectAll()); | 452 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
| 453 | 453 |
| 454 // Try editing the location bar text -- should be disallowed. | 454 // Try editing the location bar text -- should be disallowed. |
| 455 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_S, 0)); | 455 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_S, 0)); |
| 456 EXPECT_EQ(ASCIIToUTF16("Hello world"), omnibox_view->GetText()); | 456 EXPECT_EQ(ASCIIToUTF16("Hello world"), omnibox_view->GetText()); |
| 457 EXPECT_TRUE(omnibox_view->IsSelectAll()); | 457 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
| 458 | 458 |
| 459 ASSERT_NO_FATAL_FAILURE( | 459 ASSERT_NO_FATAL_FAILURE( |
| 460 SendKeyForBrowser(popup, ui::VKEY_X, kCtrlOrCmdMask)); | 460 SendKeyForBrowser(popup, ui::VKEY_X, kCtrlOrCmdMask)); |
| 461 EXPECT_EQ(ASCIIToUTF16("Hello world"), omnibox_view->GetText()); | 461 EXPECT_EQ(ASCIIToUTF16("Hello world"), omnibox_view->GetText()); |
| 462 EXPECT_TRUE(omnibox_view->IsSelectAll()); | 462 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
| 463 | 463 |
| 464 #if !defined(OS_CHROMEOS) && !defined(OS_MACOSX) | 464 #if !defined(OS_CHROMEOS) && !defined(OS_MACOSX) |
| 465 // Try alt-f4 to close the popup. | 465 // Try alt-f4 to close the popup. |
| 466 ASSERT_TRUE(SendKeyAndWait( | 466 ASSERT_TRUE(SendKeyAndWait( |
| 467 popup, ui::VKEY_F4, ui::EF_ALT_DOWN, | 467 popup, ui::VKEY_F4, ui::EF_ALT_DOWN, |
| 468 NotificationType::BROWSER_CLOSED, Source<Browser>(popup))); | 468 chrome::NOTIFICATION_BROWSER_CLOSED, Source<Browser>(popup))); |
| 469 #endif | 469 #endif |
| 470 } | 470 } |
| 471 | 471 |
| 472 void BackspaceInKeywordModeTest() { | 472 void BackspaceInKeywordModeTest() { |
| 473 OmniboxView* omnibox_view = NULL; | 473 OmniboxView* omnibox_view = NULL; |
| 474 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 474 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
| 475 | 475 |
| 476 // Trigger keyword hint mode. | 476 // Trigger keyword hint mode. |
| 477 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); | 477 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); |
| 478 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); | 478 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); |
| (...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 PersistKeywordModeOnTabSwitch) { | 1400 PersistKeywordModeOnTabSwitch) { |
| 1401 PersistKeywordModeOnTabSwitch(); | 1401 PersistKeywordModeOnTabSwitch(); |
| 1402 } | 1402 } |
| 1403 | 1403 |
| 1404 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, | 1404 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, |
| 1405 CtrlKeyPressedWithInlineAutocompleteTest) { | 1405 CtrlKeyPressedWithInlineAutocompleteTest) { |
| 1406 CtrlKeyPressedWithInlineAutocompleteTest(); | 1406 CtrlKeyPressedWithInlineAutocompleteTest(); |
| 1407 } | 1407 } |
| 1408 | 1408 |
| 1409 #endif | 1409 #endif |
| OLD | NEW |