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

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

Issue 14027009: Crash when taking screenshot onto Chrome OS Google Drive (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: improved 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/ash/screenshot_taker.h" 5 #include "chrome/browser/ui/ash/screenshot_taker.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 screenshot_result_ = screenshot_result; 56 screenshot_result_ = screenshot_result;
57 screenshot_path_ = screenshot_path; 57 screenshot_path_ = screenshot_path;
58 if (!running_) 58 if (!running_)
59 return; 59 return;
60 message_loop_runner_->Quit(); 60 message_loop_runner_->Quit();
61 running_ = false; 61 running_ = false;
62 } 62 }
63 63
64 protected: 64 protected:
65 // ScreenshotTakerTest is a friend of ScreenshotTaker and therefore 65 // ScreenshotTakerTest is a friend of ScreenshotTaker and therefore
66 // allowed to set the directory and basename. 66 // allowed to set the directory, basename and profile.
67 void SetScreenshotDirectoryForTest( 67 void SetScreenshotDirectoryForTest(
68 ScreenshotTaker* screenshot_taker, 68 ScreenshotTaker* screenshot_taker,
69 const base::FilePath& screenshot_directory) { 69 const base::FilePath& screenshot_directory) {
70 screenshot_taker->SetScreenshotDirectoryForTest(screenshot_directory); 70 screenshot_taker->SetScreenshotDirectoryForTest(screenshot_directory);
71 } 71 }
72 void SetScreenshotBasenameForTest( 72 void SetScreenshotBasenameForTest(
73 ScreenshotTaker* screenshot_taker, 73 ScreenshotTaker* screenshot_taker,
74 const std::string& screenshot_basename) { 74 const std::string& screenshot_basename) {
75 screenshot_taker->SetScreenshotBasenameForTest(screenshot_basename); 75 screenshot_taker->SetScreenshotBasenameForTest(screenshot_basename);
76 } 76 }
77 void SetScreenshotProfileForTest(
78 ScreenshotTaker* screenshot_taker,
79 Profile* profile) {
80 screenshot_taker->SetScreenshotProfileForTest(profile);
81 }
77 82
78 void Wait() { 83 void Wait() {
79 if (screenshot_complete_) 84 if (screenshot_complete_)
80 return; 85 return;
81 running_ = true; 86 running_ = true;
82 message_loop_runner_ = new content::MessageLoopRunner; 87 message_loop_runner_ = new content::MessageLoopRunner;
83 message_loop_runner_->Run(); 88 message_loop_runner_->Run();
84 EXPECT_TRUE(screenshot_complete_); 89 EXPECT_TRUE(screenshot_complete_);
85 } 90 }
86 91
87 scoped_ptr<ScopedTestingLocalState> local_state_; 92 scoped_ptr<ScopedTestingLocalState> local_state_;
88 content::TestBrowserThread ui_thread_; 93 content::TestBrowserThread ui_thread_;
89 bool running_; 94 bool running_;
90 bool screenshot_complete_; 95 bool screenshot_complete_;
91 ScreenshotTakerObserver::Result screenshot_result_; 96 ScreenshotTakerObserver::Result screenshot_result_;
92 base::FilePath screenshot_path_; 97 base::FilePath screenshot_path_;
93 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 98 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
94 99
95 DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerTest); 100 DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerTest);
96 }; 101 };
97 102
98 TEST_F(ScreenshotTakerTest, TakeScreenshot) { 103 TEST_F(ScreenshotTakerTest, TakeScreenshot) {
99 TestingProfile profile; 104 TestingProfile profile;
100 ScreenshotTaker screenshot_taker(&profile); 105 ScreenshotTaker screenshot_taker;
101 screenshot_taker.AddObserver(this); 106 screenshot_taker.AddObserver(this);
102 base::ScopedTempDir directory; 107 base::ScopedTempDir directory;
103 ASSERT_TRUE(directory.CreateUniqueTempDir()); 108 ASSERT_TRUE(directory.CreateUniqueTempDir());
104 SetScreenshotDirectoryForTest(&screenshot_taker, directory.path()); 109 SetScreenshotDirectoryForTest(&screenshot_taker, directory.path());
105 SetScreenshotBasenameForTest(&screenshot_taker, "Screenshot"); 110 SetScreenshotBasenameForTest(&screenshot_taker, "Screenshot");
111 SetScreenshotProfileForTest(&screenshot_taker, &profile);
106 112
107 EXPECT_TRUE(screenshot_taker.CanTakeScreenshot()); 113 EXPECT_TRUE(screenshot_taker.CanTakeScreenshot());
108 114
109 screenshot_taker.HandleTakePartialScreenshot( 115 screenshot_taker.HandleTakePartialScreenshot(
110 Shell::GetPrimaryRootWindow(), gfx::Rect(0, 0, 100, 100)); 116 Shell::GetPrimaryRootWindow(), gfx::Rect(0, 0, 100, 100));
111 117
112 EXPECT_FALSE(screenshot_taker.CanTakeScreenshot()); 118 EXPECT_FALSE(screenshot_taker.CanTakeScreenshot());
113 119
114 Wait(); 120 Wait();
115 121
116 #if defined(OS_CHROMEOS) 122 #if defined(OS_CHROMEOS)
117 // Screenshot notifications on Windows not yet turned on. 123 // Screenshot notifications on Windows not yet turned on.
118 EXPECT_TRUE(g_browser_process->notification_ui_manager()->DoesIdExist( 124 EXPECT_TRUE(g_browser_process->notification_ui_manager()->DoesIdExist(
119 std::string("screenshot_001"))); 125 std::string("screenshot")));
120 g_browser_process->notification_ui_manager()->CancelAll(); 126 g_browser_process->notification_ui_manager()->CancelAll();
121 #endif 127 #endif
122 128
123 EXPECT_EQ(ScreenshotTakerObserver::SCREENSHOT_SUCCESS, screenshot_result_); 129 EXPECT_EQ(ScreenshotTakerObserver::SCREENSHOT_SUCCESS, screenshot_result_);
124 130
125 if (ScreenshotTakerObserver::SCREENSHOT_SUCCESS == screenshot_result_) 131 if (ScreenshotTakerObserver::SCREENSHOT_SUCCESS == screenshot_result_)
126 EXPECT_TRUE(file_util::PathExists(screenshot_path_)); 132 EXPECT_TRUE(file_util::PathExists(screenshot_path_));
127 } 133 }
128 134
129 } // namespace test 135 } // namespace test
130 } // namespace ash 136 } // namespace ash
OLDNEW
« chrome/browser/ui/ash/screenshot_taker.cc ('K') | « chrome/browser/ui/ash/screenshot_taker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698