Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(674)

Unified Diff: chrome/browser/ui/ash/screenshot_taker_browsertest.cc

Issue 13105002: Screenshot effect non-obvious (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: observer for test Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..8dd6bd6735885958d93a8a44a6c971828064af0c
--- /dev/null
+++ b/chrome/browser/ui/ash/screenshot_taker_browsertest.cc
@@ -0,0 +1,99 @@
+// 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 "base/stringprintf.h"
+#include "base/time.h"
James Cook 2013/03/29 20:00:32 Do you need "time.h"?
sschmitz 2013/03/29 21:02:35 Removed.
+#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_(Screenshot::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(
+ Screenshot::Result screenshot_result,
+ const base::FilePath& screenshot_path) OVERRIDE {
+ screenshot_complete_ = true;
+ screenshot_result_ = screenshot_result;
+ screenshot_path_ = screenshot_path;
James Cook 2013/03/29 20:00:32 Do you need screenshot_path_?
sschmitz 2013/03/29 21:02:35 Added a test to verify that the file exists (if sc
+ 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_);
+ }
+
+ void RunTest() {
James Cook 2013/03/29 20:00:32 We usually put most of this code in the IN_PROC_BR
sschmitz 2013/03/29 21:02:35 Done.
+ 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(
+ base::StringPrintf("screenshot_%3.3d", 1)));
James Cook 2013/03/29 20:00:32 Do you need StringPrintf here? Why not just provid
sschmitz 2013/03/29 21:02:35 Done.
+
+ EXPECT_EQ(Screenshot::SCREENSHOT_SUCCESS, screenshot_result_);
+ }
+
+ bool running_;
+ bool screenshot_complete_;
+ Screenshot::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) {
+ RunTest();
+}
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698