| Index: chrome/browser/ui/ash/screenshot_taker_browsertest.cc
|
| diff --git a/chrome/browser/ui/ash/screenshot_taker_browsertest.cc b/chrome/browser/ui/ash/screenshot_taker_browsertest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..298a5bee109c0527c5ffcfde9cd2f34a77d4b276
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/ash/screenshot_taker_browsertest.cc
|
| @@ -0,0 +1,96 @@
|
| +// 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.
|
| +
|
| +#if defined(OS_CHROMEOS)
|
| +
|
| +#include "ash/shell.h"
|
| +#include "base/bind.h"
|
| +#include "base/command_line.h"
|
| +#include "base/files/scoped_temp_dir.h"
|
| +#include "base/message_loop.h"
|
| +#include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/notifications/notification_ui_manager.h"
|
| +#include "chrome/browser/ui/ash/screenshot_taker.h"
|
| +#include "chrome/common/chrome_notification_types.h"
|
| +#include "chrome/test/base/in_process_browser_test.h"
|
| +#include "content/public/test/test_utils.h"
|
| +#include "ui/aura/root_window.h"
|
| +#include "ui/message_center/message_center_switches.h"
|
| +
|
| +class ScreenshotTakerTest : public InProcessBrowserTest,
|
| + public ScreenshotTakerObserver {
|
| + public:
|
| + ScreenshotTakerTest()
|
| + : running_(false),
|
| + screenshot_complete_(false),
|
| + screenshot_result_(ScreenshotTakerObserver::SCREENSHOT_SUCCESS) {
|
| + }
|
| +
|
| + virtual ~ScreenshotTakerTest() {}
|
| +
|
| + // Overridden from InProcessBrowserTest
|
| + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
|
| + command_line->AppendSwitch(
|
| + message_center::switches::kEnableRichNotifications);
|
| + }
|
| +
|
| + // Overridden from ScreenshotTakerObserver
|
| + virtual void OnScreenshotCompleted(
|
| + ScreenshotTakerObserver::Result screenshot_result,
|
| + const base::FilePath& screenshot_path) OVERRIDE {
|
| + screenshot_complete_ = true;
|
| + screenshot_result_ = screenshot_result;
|
| + screenshot_path_ = screenshot_path;
|
| + if (!running_)
|
| + return;
|
| + message_loop_runner_->Quit();
|
| + running_ = false;
|
| + }
|
| +
|
| + protected:
|
| + void Wait() {
|
| + if (screenshot_complete_)
|
| + return;
|
| + running_ = true;
|
| + message_loop_runner_ = new content::MessageLoopRunner;
|
| + message_loop_runner_->Run();
|
| + EXPECT_TRUE(screenshot_complete_);
|
| + }
|
| +
|
| + bool running_;
|
| + bool screenshot_complete_;
|
| + ScreenshotTakerObserver::Result screenshot_result_;
|
| + base::FilePath screenshot_path_;
|
| + scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerTest);
|
| +};
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ScreenshotTakerTest, TakeScreenshot) {
|
| + ScreenshotTaker screenshot_taker;
|
| + ScreenshotTaker::SetObserverForTest(this);
|
| + base::ScopedTempDir directory;
|
| + bool created_temp_dir = directory.CreateUniqueTempDir();
|
| + ASSERT_TRUE(created_temp_dir);
|
| + screenshot_taker.SetScreenshotDirectoryForTest(directory.path());
|
| +
|
| + EXPECT_TRUE(screenshot_taker.CanTakeScreenshot());
|
| +
|
| + screenshot_taker.HandleTakePartialScreenshot(
|
| + ash::Shell::GetPrimaryRootWindow(), gfx::Rect(0,0,100,100));
|
| +
|
| + EXPECT_FALSE(screenshot_taker.CanTakeScreenshot());
|
| +
|
| + Wait();
|
| +
|
| + EXPECT_TRUE(g_browser_process->notification_ui_manager()->DoesIdExist(
|
| + std::string("screenshot_001")));
|
| +
|
| + EXPECT_EQ(ScreenshotTakerObserver::SCREENSHOT_SUCCESS, screenshot_result_);
|
| +
|
| + if (ScreenshotTakerObserver::SCREENSHOT_SUCCESS == screenshot_result_)
|
| + EXPECT_TRUE(file_util::PathExists(screenshot_path_));
|
| +}
|
| +
|
| +#endif
|
|
|