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

Side by Side Diff: ui/snapshot/snapshot_aura_unittest.cc

Issue 145293007: ui: No more TestCompositor. Use NullDraw contexts in unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: testsnulldraw: Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "ui/snapshot/snapshot.h" 5 #include "ui/snapshot/snapshot.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/test/test_simple_task_runner.h" 8 #include "base/test/test_simple_task_runner.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/aura/root_window.h" 10 #include "ui/aura/root_window.h"
11 #include "ui/aura/test/aura_test_helper.h" 11 #include "ui/aura/test/aura_test_helper.h"
12 #include "ui/aura/test/test_screen.h" 12 #include "ui/aura/test/test_screen.h"
13 #include "ui/aura/test/test_window_delegate.h" 13 #include "ui/aura/test/test_window_delegate.h"
14 #include "ui/aura/test/test_windows.h" 14 #include "ui/aura/test/test_windows.h"
15 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
16 #include "ui/compositor/layer.h" 16 #include "ui/compositor/layer.h"
17 #include "ui/compositor/test/context_factories_for_test.h"
17 #include "ui/compositor/test/draw_waiter_for_test.h" 18 #include "ui/compositor/test/draw_waiter_for_test.h"
18 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/gfx_paths.h" 20 #include "ui/gfx/gfx_paths.h"
20 #include "ui/gfx/image/image.h" 21 #include "ui/gfx/image/image.h"
21 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
22 #include "ui/gfx/size_conversions.h" 23 #include "ui/gfx/size_conversions.h"
23 #include "ui/gfx/transform.h" 24 #include "ui/gfx/transform.h"
24 #include "ui/gl/gl_implementation.h" 25 #include "ui/gl/gl_implementation.h"
25 26
26 namespace ui { 27 namespace ui {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 77
77 } // namespace 78 } // namespace
78 79
79 class SnapshotAuraTest : public testing::Test { 80 class SnapshotAuraTest : public testing::Test {
80 public: 81 public:
81 SnapshotAuraTest() {} 82 SnapshotAuraTest() {}
82 virtual ~SnapshotAuraTest() {} 83 virtual ~SnapshotAuraTest() {}
83 84
84 virtual void SetUp() OVERRIDE { 85 virtual void SetUp() OVERRIDE {
85 testing::Test::SetUp(); 86 testing::Test::SetUp();
87
88 // The ContextFactory must exist before any Compositors are created.
89 // Snapshot test tests real drawing and readback, so needs pixel output.
90 bool enable_pixel_output = true;
91 ui::InitializeContextFactoryForTests(enable_pixel_output);
92
86 helper_.reset( 93 helper_.reset(
87 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); 94 new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
88 // Snapshot test tests real drawing and readback, so needs a real context. 95 helper_->SetUp();
89 bool allow_test_contexts = false;
90 helper_->SetUp(allow_test_contexts);
91 } 96 }
92 97
93 virtual void TearDown() OVERRIDE { 98 virtual void TearDown() OVERRIDE {
94 test_window_.reset(); 99 test_window_.reset();
95 delegate_.reset(); 100 delegate_.reset();
96 helper_->RunAllPendingInMessageLoop(); 101 helper_->RunAllPendingInMessageLoop();
97 helper_->TearDown(); 102 helper_->TearDown();
103 ui::TerminateContextFactoryForTests();
98 testing::Test::TearDown(); 104 testing::Test::TearDown();
99 } 105 }
100 106
101 protected: 107 protected:
102 aura::Window* test_window() { return test_window_.get(); } 108 aura::Window* test_window() { return test_window_.get(); }
103 aura::Window* root_window() { return helper_->root_window(); } 109 aura::Window* root_window() { return helper_->root_window(); }
104 aura::WindowEventDispatcher* dispatcher() { return helper_->dispatcher(); } 110 aura::WindowEventDispatcher* dispatcher() { return helper_->dispatcher(); }
105 aura::TestScreen* test_screen() { return helper_->test_screen(); } 111 aura::TestScreen* test_screen() { return helper_->test_screen(); }
106 112
107 void WaitForDraw() { 113 void WaitForDraw() {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 gfx::SizeF snapshot_size(test_bounds.size()); 279 gfx::SizeF snapshot_size(test_bounds.size());
274 snapshot_size.Scale(2.0f); 280 snapshot_size.Scale(2.0f);
275 281
276 gfx::Image snapshot = GrabSnapshotForTestWindow(); 282 gfx::Image snapshot = GrabSnapshotForTestWindow();
277 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), 283 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(),
278 snapshot.Size().ToString()); 284 snapshot.Size().ToString());
279 EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2)); 285 EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2));
280 } 286 }
281 287
282 } // namespace ui 288 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698