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

Side by Side Diff: chrome/browser/ui/ash/screenshot_taker_unittest.cc

Issue 13105002: Screenshot effect non-obvious (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: cleanup 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
« no previous file with comments | « chrome/browser/ui/ash/screenshot_taker.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/ui/ash/screenshot_taker.h"
6
7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h"
9 #include "base/bind.h"
10 #include "base/command_line.h"
11 #include "base/file_util.h"
12 #include "base/files/scoped_temp_dir.h"
13 #include "base/message_loop.h"
14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/notifications/notification_ui_manager.h"
16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/scoped_testing_local_state.h"
18 #include "chrome/test/base/testing_browser_process.h"
19 #include "chrome/test/base/testing_profile.h"
20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/test/test_browser_thread.h"
22 #include "content/public/test/test_utils.h"
23 #include "ui/aura/root_window.h"
24 #include "ui/message_center/message_center_switches.h"
25
26 namespace ash {
27 namespace test {
28
29 class ScreenshotTakerTest : public AshTestBase,
30 public ScreenshotTakerObserver {
31 public:
32 ScreenshotTakerTest()
33 : local_state_(TestingBrowserProcess::GetGlobal()),
34 ui_thread_(content::BrowserThread::UI, message_loop()),
35 running_(false),
36 screenshot_complete_(false),
37 screenshot_result_(ScreenshotTakerObserver::SCREENSHOT_SUCCESS) {
38 }
39
40 // Overridden from ScreenshotTakerObserver
41 virtual void OnScreenshotCompleted(
42 ScreenshotTakerObserver::Result screenshot_result,
43 const base::FilePath& screenshot_path) OVERRIDE {
44 screenshot_complete_ = true;
45 screenshot_result_ = screenshot_result;
46 screenshot_path_ = screenshot_path;
47 if (!running_)
48 return;
49 message_loop_runner_->Quit();
50 running_ = false;
51 }
52
53 protected:
54 // ScreenshotTakerTest is a friend of ScreenshotTaker and therefore
55 // allowed to set the directory and basename.
56 void SetScreenshotDirectoryForTest(
57 ScreenshotTaker* screenshot_taker,
58 const base::FilePath& screenshot_directory) {
59 screenshot_taker->SetScreenshotDirectoryForTest(screenshot_directory);
60 }
61 void SetScreenshotBasenameForTest(
62 ScreenshotTaker* screenshot_taker,
63 const std::string& screenshot_basename) {
64 screenshot_taker->SetScreenshotBasenameForTest(screenshot_basename);
65 }
66
67 void Wait() {
68 if (screenshot_complete_)
69 return;
70 running_ = true;
71 message_loop_runner_ = new content::MessageLoopRunner;
72 message_loop_runner_->Run();
73 EXPECT_TRUE(screenshot_complete_);
74 }
75
76 ScopedTestingLocalState local_state_;
77 content::TestBrowserThread ui_thread_;
78 bool running_;
79 bool screenshot_complete_;
80 ScreenshotTakerObserver::Result screenshot_result_;
81 base::FilePath screenshot_path_;
82 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
83
84 DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerTest);
85 };
86
87 TEST_F(ScreenshotTakerTest, TakeScreenshot) {
88 TestingProfile profile;
89 ScreenshotTaker screenshot_taker(&profile);
90 screenshot_taker.AddObserver(this);
91 base::ScopedTempDir directory;
92 ASSERT_TRUE(directory.CreateUniqueTempDir());
93 SetScreenshotDirectoryForTest(&screenshot_taker, directory.path());
94 SetScreenshotBasenameForTest(&screenshot_taker, "Screenshot");
95
96 EXPECT_TRUE(screenshot_taker.CanTakeScreenshot());
97
98 screenshot_taker.HandleTakePartialScreenshot(
99 Shell::GetPrimaryRootWindow(), gfx::Rect(0, 0, 100, 100));
100
101 EXPECT_FALSE(screenshot_taker.CanTakeScreenshot());
102
103 Wait();
104
105 #if defined(OS_CHROMEOS)
106 // Screenshot notifications on Windows not yet turned on.
107 EXPECT_TRUE(g_browser_process->notification_ui_manager()->DoesIdExist(
108 std::string("screenshot_001")));
109 #endif
110
111 EXPECT_EQ(ScreenshotTakerObserver::SCREENSHOT_SUCCESS, screenshot_result_);
112
113 if (ScreenshotTakerObserver::SCREENSHOT_SUCCESS == screenshot_result_)
114 EXPECT_TRUE(file_util::PathExists(screenshot_path_));
115 }
116
117 } // namespace test
118 } // namespace ash
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/screenshot_taker.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698