 Chromium Code Reviews
 Chromium Code Reviews Issue 13105002:
  Screenshot effect non-obvious  (Closed) 
  Base URL: http://git.chromium.org/chromium/src.git@master
    
  
    Issue 13105002:
  Screenshot effect non-obvious  (Closed) 
  Base URL: http://git.chromium.org/chromium/src.git@master| 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..ec364097c2fe7885e002f29663ca3b21e3a69043 | 
| --- /dev/null | 
| +++ b/chrome/browser/ui/ash/screenshot_taker_browsertest.cc | 
| @@ -0,0 +1,97 @@ | 
| +// 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) | 
| 
sky
2013/03/31 01:16:03
This isn't the right way to have a chromeos specif
 
sschmitz
2013/04/02 21:23:25
Removed ifdef Chrome OS
 | 
| + | 
| +#include "ash/shell.h" | 
| +#include "base/bind.h" | 
| +#include "base/command_line.h" | 
| +#include "base/file_util.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, | 
| 
sky
2013/03/31 01:16:03
Why does this need to be a browser test instead of
 
sschmitz
2013/04/02 21:23:25
Changed to unit test
 | 
| + 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 |