OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/location.h" | 6 #include "base/location.h" |
7 #include "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 401 |
402 // http://crbug.com/177163 | 402 // http://crbug.com/177163 |
403 #if defined(OS_WIN) && !defined(NDEBUG) | 403 #if defined(OS_WIN) && !defined(NDEBUG) |
404 #define MAYBE_TabIndicator DISABLED_TabIndicator | 404 #define MAYBE_TabIndicator DISABLED_TabIndicator |
405 #else | 405 #else |
406 // Also flaky everywhere else: https://crbug.com/530657 | 406 // Also flaky everywhere else: https://crbug.com/530657 |
407 #define MAYBE_TabIndicator DISABLED_TabIndicator | 407 #define MAYBE_TabIndicator DISABLED_TabIndicator |
408 #endif | 408 #endif |
409 // Tests that the tab indicator (in the tab strip) is shown during tab capture. | 409 // Tests that the tab indicator (in the tab strip) is shown during tab capture. |
410 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_TabIndicator) { | 410 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_TabIndicator) { |
411 ASSERT_EQ(TAB_MEDIA_STATE_NONE, | 411 ASSERT_EQ(TabAlertState::NONE, |
412 chrome::GetTabMediaStateForContents( | 412 chrome::GetTabAlertStateForContents( |
413 browser()->tab_strip_model()->GetActiveWebContents())); | 413 browser()->tab_strip_model()->GetActiveWebContents())); |
414 | 414 |
415 // Run an extension test that just turns on tab capture, which should cause | 415 // Run an extension test that just turns on tab capture, which should cause |
416 // the indicator to turn on. | 416 // the indicator to turn on. |
417 AddExtensionToCommandLineWhitelist(); | 417 AddExtensionToCommandLineWhitelist(); |
418 ASSERT_TRUE(RunExtensionSubtest("tab_capture", "start_tab_capture.html")) | 418 ASSERT_TRUE(RunExtensionSubtest("tab_capture", "start_tab_capture.html")) |
419 << message_; | 419 << message_; |
420 | 420 |
421 // A TabStripModelObserver that quits the MessageLoop whenever the UI's model | 421 // A TabStripModelObserver that quits the MessageLoop whenever the UI's model |
422 // is sent an event that changes the indicator status. | 422 // is sent an event that changes the indicator status. |
423 class IndicatorChangeObserver : public TabStripModelObserver { | 423 class IndicatorChangeObserver : public TabStripModelObserver { |
424 public: | 424 public: |
425 explicit IndicatorChangeObserver(Browser* browser) | 425 explicit IndicatorChangeObserver(Browser* browser) |
426 : last_media_state_(chrome::GetTabMediaStateForContents( | 426 : last_alert_state_(chrome::GetTabAlertStateForContents( |
427 browser->tab_strip_model()->GetActiveWebContents())) {} | 427 browser->tab_strip_model()->GetActiveWebContents())) {} |
428 | 428 |
429 TabMediaState last_media_state() const { return last_media_state_; } | 429 TabAlertState last_alert_state() const { return last_alert_state_; } |
430 | 430 |
431 void TabChangedAt(content::WebContents* contents, | 431 void TabChangedAt(content::WebContents* contents, |
432 int index, | 432 int index, |
433 TabChangeType change_type) override { | 433 TabChangeType change_type) override { |
434 const TabMediaState media_state = | 434 const TabAlertState alert_state = |
435 chrome::GetTabMediaStateForContents(contents); | 435 chrome::GetTabAlertStateForContents(contents); |
436 const bool has_changed = media_state != last_media_state_; | 436 const bool has_changed = alert_state != last_alert_state_; |
437 last_media_state_ = media_state; | 437 last_alert_state_ = alert_state; |
438 if (has_changed) { | 438 if (has_changed) { |
439 base::ThreadTaskRunnerHandle::Get()->PostTask( | 439 base::ThreadTaskRunnerHandle::Get()->PostTask( |
440 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 440 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
441 } | 441 } |
442 } | 442 } |
443 | 443 |
444 private: | 444 private: |
445 TabMediaState last_media_state_; | 445 TabAlertState last_alert_state_; |
446 }; | 446 }; |
447 | 447 |
448 // Run the browser until the indicator turns on. | 448 // Run the browser until the indicator turns on. |
449 IndicatorChangeObserver observer(browser()); | 449 IndicatorChangeObserver observer(browser()); |
450 browser()->tab_strip_model()->AddObserver(&observer); | 450 browser()->tab_strip_model()->AddObserver(&observer); |
451 const base::TimeTicks start_time = base::TimeTicks::Now(); | 451 const base::TimeTicks start_time = base::TimeTicks::Now(); |
452 while (observer.last_media_state() != TAB_MEDIA_STATE_CAPTURING) { | 452 while (observer.last_alert_state() != TabAlertState::TAB_CAPTURING) { |
453 if (base::TimeTicks::Now() - start_time > | 453 if (base::TimeTicks::Now() - start_time > |
454 base::TimeDelta::FromSeconds(10)) { | 454 base::TimeDelta::FromSeconds(10)) { |
455 EXPECT_EQ(TAB_MEDIA_STATE_CAPTURING, observer.last_media_state()); | 455 EXPECT_EQ(TabAlertState::TAB_CAPTURING, observer.last_alert_state()); |
456 browser()->tab_strip_model()->RemoveObserver(&observer); | 456 browser()->tab_strip_model()->RemoveObserver(&observer); |
457 return; | 457 return; |
458 } | 458 } |
459 content::RunMessageLoop(); | 459 content::RunMessageLoop(); |
460 } | 460 } |
461 browser()->tab_strip_model()->RemoveObserver(&observer); | 461 browser()->tab_strip_model()->RemoveObserver(&observer); |
462 } | 462 } |
463 | 463 |
464 } // namespace | 464 } // namespace |
465 | 465 |
466 } // namespace extensions | 466 } // namespace extensions |
OLD | NEW |