| Index: chrome/browser/media/ash_desktop_media_list_unittest.cc
|
| diff --git a/chrome/browser/media/ash_desktop_media_list_unittest.cc b/chrome/browser/media/ash_desktop_media_list_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7042fc6220cb7d0fce1c80e6562d50b39f0f9320
|
| --- /dev/null
|
| +++ b/chrome/browser/media/ash_desktop_media_list_unittest.cc
|
| @@ -0,0 +1,100 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/media/ash_desktop_media_list.h"
|
| +
|
| +#include "ash/test/ash_test_base.h"
|
| +#include "base/message_loop/message_loop.h"
|
| +#include "chrome/browser/media/desktop_media_list_observer.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/aura/window.h"
|
| +#include "ui/compositor/test/test_context_factory.h"
|
| +
|
| +int kThumbnailSize = 100;
|
| +
|
| +class MockDesktopMediaListObserver : public DesktopMediaListObserver {
|
| + public:
|
| + MOCK_METHOD1(OnSourceAdded, void(int index));
|
| + MOCK_METHOD1(OnSourceRemoved, void(int index));
|
| + MOCK_METHOD1(OnSourceNameChanged, void(int index));
|
| + MOCK_METHOD1(OnSourceThumbnailChanged, void(int index));
|
| +};
|
| +
|
| +
|
| +class AshDesktopMediaListTest : public ash::test::AshTestBase {
|
| + public:
|
| + AshDesktopMediaListTest() {}
|
| + virtual ~AshDesktopMediaListTest() {}
|
| +
|
| + void CreateList(int source_types) {
|
| + list_.reset(new AshDesktopMediaList(source_types));
|
| + list_->SetUpdatePeriod(base::TimeDelta::FromMilliseconds(0));
|
| + list_->SetThumbnailSize(gfx::Size(kThumbnailSize, kThumbnailSize));
|
| + }
|
| +
|
| + protected:
|
| + MockDesktopMediaListObserver observer_;
|
| + scoped_ptr<AshDesktopMediaList> list_;
|
| + DISALLOW_COPY_AND_ASSIGN(AshDesktopMediaListTest);
|
| +};
|
| +
|
| +ACTION(QuitMessageLoop) {
|
| + base::MessageLoop::current()->PostTask(
|
| + FROM_HERE, base::MessageLoop::QuitClosure());
|
| +}
|
| +
|
| +TEST_F(AshDesktopMediaListTest, Screen) {
|
| + CreateList(AshDesktopMediaList::SCREENS | AshDesktopMediaList::WINDOWS);
|
| +
|
| + EXPECT_CALL(observer_, OnSourceAdded(0))
|
| + .WillOnce(QuitMessageLoop());
|
| + list_->StartUpdating(&observer_);
|
| + base::MessageLoop::current()->Run();
|
| +}
|
| +
|
| +TEST_F(AshDesktopMediaListTest, OneWindow) {
|
| + CreateList(AshDesktopMediaList::SCREENS | AshDesktopMediaList::WINDOWS);
|
| +
|
| + scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
|
| +
|
| + EXPECT_CALL(observer_, OnSourceAdded(0));
|
| + EXPECT_CALL(observer_, OnSourceAdded(1))
|
| + .WillOnce(QuitMessageLoop());
|
| + EXPECT_CALL(observer_, OnSourceRemoved(1))
|
| + .WillOnce(QuitMessageLoop());
|
| +
|
| + list_->StartUpdating(&observer_);
|
| + base::MessageLoop::current()->Run();
|
| + window.reset();
|
| + base::MessageLoop::current()->Run();
|
| +}
|
| +
|
| +TEST_F(AshDesktopMediaListTest, ScreenOnly) {
|
| + CreateList(AshDesktopMediaList::SCREENS | AshDesktopMediaList::WINDOWS);
|
| +
|
| + scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
|
| +
|
| + EXPECT_CALL(observer_, OnSourceAdded(0))
|
| + .WillOnce(QuitMessageLoop());
|
| +
|
| + list_->StartUpdating(&observer_);
|
| + base::MessageLoop::current()->Run();
|
| +}
|
| +
|
| +TEST_F(AshDesktopMediaListTest, WindowOnly) {
|
| + CreateList(AshDesktopMediaList::WINDOWS);
|
| +
|
| + scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
|
| +
|
| + EXPECT_CALL(observer_, OnSourceAdded(0))
|
| + .WillOnce(QuitMessageLoop());
|
| + EXPECT_CALL(observer_, OnSourceRemoved(0))
|
| + .WillOnce(QuitMessageLoop());
|
| +
|
| + list_->StartUpdating(&observer_);
|
| + base::MessageLoop::current()->Run();
|
| + window.reset();
|
| + base::MessageLoop::current()->Run();
|
| +}
|
|
|