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

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: unittest 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..bf4a7ac7bef36a61e92244deb11fcd352a9e16f0
--- /dev/null
+++ b/chrome/browser/ui/ash/screenshot_taker_browsertest.cc
@@ -0,0 +1,76 @@
+// 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/message_loop.h"
+#include "base/stringprintf.h"
+#include "base/time.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/test/base/in_process_browser_test.h"
+#include "ui/aura/root_window.h"
+#include "ui/message_center/message_center_switches.h"
+
+class ScreenshotTakerTest : public InProcessBrowserTest {
+ public:
+ ScreenshotTakerTest() {}
+ virtual ~ScreenshotTakerTest() {}
+
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ command_line->AppendSwitch(
+ message_center::switches::kEnableRichNotifications);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerTest);
+};
+
+namespace {
+// Saving screenshots to file happens on a blocking pool thread. When
+// completed, a notification is added (from the browser ui thread).
+// We repeatedly check for this notification to be present or exit
James Cook 2013/03/28 19:49:36 You can't write browser tests in Chrome this way (
sschmitz 2013/03/28 23:52:41 Thanks for the info... done.
+// with a time-out error. On my Linux desktop success is reached typically
+// on the 2nd or 3rd invocation of check_for_notification within < ~20 msec.
+void check_for_notification(std::string notification_id,
+ base::TimeDelta start_time) {
+ if (g_browser_process->notification_ui_manager()->DoesIdExist(
+ notification_id)) {
+ return; // success
+ }
+ base::TimeDelta delta_time = base::TimeDelta::FromInternalValue(
+ base::TimeTicks::Now().ToInternalValue()) - start_time;
+ double limit_msec = 500.0;
+ EXPECT_LT(delta_time.InMillisecondsF(), limit_msec);
+ if (delta_time.InMillisecondsF() < limit_msec) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&check_for_notification, notification_id, start_time));
+ }
+}
+}
+
+IN_PROC_BROWSER_TEST_F(ScreenshotTakerTest, TakeScreenshot) {
+ ScreenshotTaker screenshot_taker;
+ EXPECT_TRUE(screenshot_taker.CanTakeScreenshot());
+
+ screenshot_taker.HandleTakePartialScreenshot(
+ ash::Shell::GetPrimaryRootWindow(), gfx::Rect(0,0,100,100));
+ EXPECT_FALSE(screenshot_taker.CanTakeScreenshot());
+
+ std::string notification_id = base::StringPrintf("screenshot_%3.3d", 1);
+ base::TimeDelta start_time = base::TimeDelta::FromInternalValue(
+ base::TimeTicks::Now().ToInternalValue());
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&check_for_notification, notification_id, start_time));
+
+ MessageLoop::current()->RunUntilIdle();
+}
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698