OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" |
16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "chrome/browser/local_discovery/test_service_discovery_client.h" | 20 #include "chrome/browser/local_discovery/test_service_discovery_client.h" |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 22 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
22 #include "chrome/browser/signin/signin_manager_factory.h" | 23 #include "chrome/browser/signin/signin_manager_factory.h" |
23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h" | 25 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h" |
25 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 signaled_ = true; | 299 signaled_ = true; |
299 if (waiting_) | 300 if (waiting_) |
300 base::MessageLoop::current()->QuitWhenIdle(); | 301 base::MessageLoop::current()->QuitWhenIdle(); |
301 } | 302 } |
302 | 303 |
303 // Pause execution and recursively run the message loop until |Signal()| is | 304 // Pause execution and recursively run the message loop until |Signal()| is |
304 // called. Do not pause if |Signal()| has already been called. | 305 // called. Do not pause if |Signal()| has already been called. |
305 void Wait() { | 306 void Wait() { |
306 while (!signaled_) { | 307 while (!signaled_) { |
307 waiting_ = true; | 308 waiting_ = true; |
308 base::MessageLoop::current()->Run(); | 309 base::RunLoop().Run(); |
309 waiting_ = false; | 310 waiting_ = false; |
310 } | 311 } |
311 signaled_ = false; | 312 signaled_ = false; |
312 } | 313 } |
313 | 314 |
314 private: | 315 private: |
315 bool signaled_; | 316 bool signaled_; |
316 bool waiting_; | 317 bool waiting_; |
317 | 318 |
318 DISALLOW_COPY_AND_ASSIGN(TestMessageLoopCondition); | 319 DISALLOW_COPY_AND_ASSIGN(TestMessageLoopCondition); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 WebUIBrowserTest::SetUpCommandLine(command_line); | 450 WebUIBrowserTest::SetUpCommandLine(command_line); |
450 } | 451 } |
451 | 452 |
452 void RunFor(base::TimeDelta time_period) { | 453 void RunFor(base::TimeDelta time_period) { |
453 base::CancelableCallback<void()> callback( | 454 base::CancelableCallback<void()> callback( |
454 base::Bind(&base::MessageLoop::QuitWhenIdle, | 455 base::Bind(&base::MessageLoop::QuitWhenIdle, |
455 base::Unretained(base::MessageLoop::current()))); | 456 base::Unretained(base::MessageLoop::current()))); |
456 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 457 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
457 FROM_HERE, callback.callback(), time_period); | 458 FROM_HERE, callback.callback(), time_period); |
458 | 459 |
459 base::MessageLoop::current()->Run(); | 460 base::RunLoop().Run(); |
460 callback.Cancel(); | 461 callback.Cancel(); |
461 } | 462 } |
462 | 463 |
463 TestServiceDiscoveryClient* test_service_discovery_client() { | 464 TestServiceDiscoveryClient* test_service_discovery_client() { |
464 return test_service_discovery_client_.get(); | 465 return test_service_discovery_client_.get(); |
465 } | 466 } |
466 | 467 |
467 TestMessageLoopCondition& condition_devices_listed() { | 468 TestMessageLoopCondition& condition_devices_listed() { |
468 return condition_devices_listed_; | 469 return condition_devices_listed_; |
469 } | 470 } |
(...skipping 25 matching lines...) Expand all Loading... |
495 } | 496 } |
496 | 497 |
497 IN_PROC_BROWSER_TEST_F(LocalDiscoveryUITest, AddRowTest) { | 498 IN_PROC_BROWSER_TEST_F(LocalDiscoveryUITest, AddRowTest) { |
498 ui_test_utils::NavigateToURL(browser(), GURL( | 499 ui_test_utils::NavigateToURL(browser(), GURL( |
499 chrome::kChromeUIDevicesURL)); | 500 chrome::kChromeUIDevicesURL)); |
500 condition_devices_listed().Wait(); | 501 condition_devices_listed().Wait(); |
501 | 502 |
502 test_service_discovery_client()->SimulateReceive( | 503 test_service_discovery_client()->SimulateReceive( |
503 kAnnouncePacket, sizeof(kAnnouncePacket)); | 504 kAnnouncePacket, sizeof(kAnnouncePacket)); |
504 | 505 |
505 base::MessageLoop::current()->RunUntilIdle(); | 506 base::RunLoop().RunUntilIdle(); |
506 | 507 |
507 EXPECT_TRUE(WebUIBrowserTest::RunJavascriptTest("checkOneDevice")); | 508 EXPECT_TRUE(WebUIBrowserTest::RunJavascriptTest("checkOneDevice")); |
508 | 509 |
509 test_service_discovery_client()->SimulateReceive( | 510 test_service_discovery_client()->SimulateReceive( |
510 kGoodbyePacket, sizeof(kGoodbyePacket)); | 511 kGoodbyePacket, sizeof(kGoodbyePacket)); |
511 | 512 |
512 RunFor(base::TimeDelta::FromMilliseconds(1100)); | 513 RunFor(base::TimeDelta::FromMilliseconds(1100)); |
513 | 514 |
514 EXPECT_TRUE(WebUIBrowserTest::RunJavascriptTest("checkNoDevices")); | 515 EXPECT_TRUE(WebUIBrowserTest::RunJavascriptTest("checkNoDevices")); |
515 } | 516 } |
516 | 517 |
517 | 518 |
518 IN_PROC_BROWSER_TEST_F(LocalDiscoveryUITest, RegisterTest) { | 519 IN_PROC_BROWSER_TEST_F(LocalDiscoveryUITest, RegisterTest) { |
519 TestMessageLoopCondition condition_token_claimed; | 520 TestMessageLoopCondition condition_token_claimed; |
520 | 521 |
521 ui_test_utils::NavigateToURL(browser(), GURL( | 522 ui_test_utils::NavigateToURL(browser(), GURL( |
522 chrome::kChromeUIDevicesURL)); | 523 chrome::kChromeUIDevicesURL)); |
523 condition_devices_listed().Wait(); | 524 condition_devices_listed().Wait(); |
524 | 525 |
525 test_service_discovery_client()->SimulateReceive( | 526 test_service_discovery_client()->SimulateReceive( |
526 kAnnouncePacket, sizeof(kAnnouncePacket)); | 527 kAnnouncePacket, sizeof(kAnnouncePacket)); |
527 | 528 |
528 base::MessageLoop::current()->RunUntilIdle(); | 529 base::RunLoop().RunUntilIdle(); |
529 | 530 |
530 EXPECT_TRUE(WebUIBrowserTest::RunJavascriptTest("checkOneDevice")); | 531 EXPECT_TRUE(WebUIBrowserTest::RunJavascriptTest("checkOneDevice")); |
531 | 532 |
532 EXPECT_TRUE(WebUIBrowserTest::RunJavascriptTest("registerShowOverlay")); | 533 EXPECT_TRUE(WebUIBrowserTest::RunJavascriptTest("registerShowOverlay")); |
533 | 534 |
534 { | 535 { |
535 InSequence s; | 536 InSequence s; |
536 EXPECT_CALL(fake_url_fetcher_creator(), OnCreateFakeURLFetcher(kURLInfo)); | 537 EXPECT_CALL(fake_url_fetcher_creator(), OnCreateFakeURLFetcher(kURLInfo)); |
537 EXPECT_CALL(fake_url_fetcher_creator(), OnCreateFakeURLFetcher( | 538 EXPECT_CALL(fake_url_fetcher_creator(), OnCreateFakeURLFetcher( |
538 kURLRegisterStart)); | 539 kURLRegisterStart)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 EXPECT_CALL(fake_url_fetcher_creator(), OnCreateFakeURLFetcher(kURLInfo)) | 572 EXPECT_CALL(fake_url_fetcher_creator(), OnCreateFakeURLFetcher(kURLInfo)) |
572 .WillOnce(InvokeWithoutArgs(&condition_token_claimed, | 573 .WillOnce(InvokeWithoutArgs(&condition_token_claimed, |
573 &TestMessageLoopCondition::Signal)); | 574 &TestMessageLoopCondition::Signal)); |
574 } | 575 } |
575 | 576 |
576 condition_token_claimed.Wait(); | 577 condition_token_claimed.Wait(); |
577 | 578 |
578 test_service_discovery_client()->SimulateReceive( | 579 test_service_discovery_client()->SimulateReceive( |
579 kAnnouncePacketRegistered, sizeof(kAnnouncePacketRegistered)); | 580 kAnnouncePacketRegistered, sizeof(kAnnouncePacketRegistered)); |
580 | 581 |
581 base::MessageLoop::current()->RunUntilIdle(); | 582 base::RunLoop().RunUntilIdle(); |
582 | 583 |
583 EXPECT_TRUE(WebUIBrowserTest::RunJavascriptTest("expectRegisterDone")); | 584 EXPECT_TRUE(WebUIBrowserTest::RunJavascriptTest("expectRegisterDone")); |
584 } | 585 } |
585 | 586 |
586 } // namespace | 587 } // namespace |
587 | 588 |
588 } // namespace local_discovery | 589 } // namespace local_discovery |
OLD | NEW |