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

Side by Side 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: review Created 7 years, 8 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #if defined(OS_CHROMEOS)
6
7 #include "ash/shell.h"
8 #include "base/bind.h"
9 #include "base/command_line.h"
10 #include "base/files/scoped_temp_dir.h"
11 #include "base/message_loop.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/notifications/notification_ui_manager.h"
14 #include "chrome/browser/ui/ash/screenshot_taker.h"
15 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "content/public/test/test_utils.h"
18 #include "ui/aura/root_window.h"
19 #include "ui/message_center/message_center_switches.h"
20
21 class ScreenshotTakerTest : public InProcessBrowserTest,
22 public ScreenshotTakerObserver {
23 public:
24 ScreenshotTakerTest()
25 : running_(false),
26 screenshot_complete_(false),
27 screenshot_result_(ScreenshotTakerObserver::SCREENSHOT_SUCCESS) {
28 }
29
30 virtual ~ScreenshotTakerTest() {}
31
32 // Overridden from InProcessBrowserTest
33 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
34 command_line->AppendSwitch(
35 message_center::switches::kEnableRichNotifications);
36 }
37
38 // Overridden from ScreenshotTakerObserver
39 virtual void OnScreenshotCompleted(
40 ScreenshotTakerObserver::Result screenshot_result,
41 const base::FilePath& screenshot_path) OVERRIDE {
42 screenshot_complete_ = true;
43 screenshot_result_ = screenshot_result;
44 screenshot_path_ = screenshot_path;
45 if (!running_)
46 return;
47 message_loop_runner_->Quit();
48 running_ = false;
49 }
50
51 protected:
52 void Wait() {
53 if (screenshot_complete_)
54 return;
55 running_ = true;
56 message_loop_runner_ = new content::MessageLoopRunner;
57 message_loop_runner_->Run();
58 EXPECT_TRUE(screenshot_complete_);
59 }
60
61 bool running_;
62 bool screenshot_complete_;
63 ScreenshotTakerObserver::Result screenshot_result_;
64 base::FilePath screenshot_path_;
65 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
66
67 DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerTest);
68 };
69
70 IN_PROC_BROWSER_TEST_F(ScreenshotTakerTest, TakeScreenshot) {
71 ScreenshotTaker screenshot_taker;
72 ScreenshotTaker::SetObserverForTest(this);
73 base::ScopedTempDir directory;
74 bool created_temp_dir = directory.CreateUniqueTempDir();
75 ASSERT_TRUE(created_temp_dir);
76 screenshot_taker.SetScreenshotDirectoryForTest(directory.path());
77
78 EXPECT_TRUE(screenshot_taker.CanTakeScreenshot());
79
80 screenshot_taker.HandleTakePartialScreenshot(
81 ash::Shell::GetPrimaryRootWindow(), gfx::Rect(0,0,100,100));
82
83 EXPECT_FALSE(screenshot_taker.CanTakeScreenshot());
84
85 Wait();
86
87 EXPECT_TRUE(g_browser_process->notification_ui_manager()->DoesIdExist(
88 std::string("screenshot_001")));
89
90 EXPECT_EQ(ScreenshotTakerObserver::SCREENSHOT_SUCCESS, screenshot_result_);
91
92 if (ScreenshotTakerObserver::SCREENSHOT_SUCCESS == screenshot_result_)
93 EXPECT_TRUE(file_util::PathExists(screenshot_path_));
94 }
95
96 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698