190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file. 490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/snapshot/snapshot.h" 690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/bind.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/test/test_simple_task_runner.h" 990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/aura/test/aura_test_helper.h" 1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/aura/test/test_screen.h" 1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/aura/test/test_window_delegate.h" 1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/aura/test/test_windows.h" 1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/aura/window.h" 15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h" 16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/compositor/compositor.h" 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/compositor/layer.h" 18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/compositor/test/context_factories_for_test.h" 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/compositor/test/draw_waiter_for_test.h" 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/gfx/canvas.h" 2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/gfx/gfx_paths.h" 2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/gfx/image/image.h" 2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/gfx/rect.h" 2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/gfx/size_conversions.h" 2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/gfx/transform.h" 2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/gl/gl_implementation.h" 275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ui/wm/core/default_activation_client.h" 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace ui { 3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace { 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SkColor GetExpectedColorForPoint(int x, int y) { 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return SkColorSetRGB(std::min(x, 255), std::min(y, 255), 0); 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Paint simple rectangle on the specified aura window. 3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class TestPaintingWindowDelegate : public aura::test::TestWindowDelegate { 3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public: 3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) explicit TestPaintingWindowDelegate(const gfx::Size& window_size) 4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) : window_size_(window_size) { 4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual ~TestPaintingWindowDelegate() { 4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (int y = 0; y < window_size_.height(); ++y) { 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (int x = 0; x < window_size_.width(); ++x) 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) canvas->FillRect(gfx::Rect(x, y, 1, 1), GetExpectedColorForPoint(x, y)); 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private: 5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Size window_size_; 5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TestPaintingWindowDelegate); 5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)size_t GetFailedPixelsCountWithScaleFactor(const gfx::Image& image, 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int scale_factor) { 6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const SkBitmap* bitmap = image.ToSkBitmap(); 6290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) uint32* bitmap_data = reinterpret_cast<uint32*>( 6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bitmap->pixelRef()->pixels()); 6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) size_t result = 0; 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (int y = 0; y < bitmap->height(); y += scale_factor) { 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (int x = 0; x < bitmap->width(); x += scale_factor) { 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (static_cast<SkColor>(bitmap_data[x + y * bitmap->width()]) != 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetExpectedColorForPoint(x / scale_factor, y / scale_factor)) { 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ++result; 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 7290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return result; 7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)size_t GetFailedPixelsCount(const gfx::Image& image) { 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return GetFailedPixelsCountWithScaleFactor(image, 1); 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace 8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class SnapshotAuraTest : public testing::Test { 8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public: 8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SnapshotAuraTest() {} 8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual ~SnapshotAuraTest() {} 8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void SetUp() OVERRIDE { 8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) testing::Test::SetUp(); 89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 90a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // The ContextFactory must exist before any Compositors are created. 91a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Snapshot test tests real drawing and readback, so needs pixel output. 92a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool enable_pixel_output = true; 93cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ui::ContextFactory* context_factory = 94cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ui::InitializeContextFactoryForTests(enable_pixel_output); 95a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 96868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) helper_.reset( 97868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); 98cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) helper_->SetUp(context_factory); 995c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu new ::wm::DefaultActivationClient(helper_->root_window()); 10090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 10190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 10290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void TearDown() OVERRIDE { 10390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) test_window_.reset(); 10490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) delegate_.reset(); 10590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) helper_->RunAllPendingInMessageLoop(); 10690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) helper_->TearDown(); 107a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::TerminateContextFactoryForTests(); 10890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) testing::Test::TearDown(); 10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 11090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) protected: 11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) aura::Window* test_window() { return test_window_.get(); } 113f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) aura::Window* root_window() { return helper_->root_window(); } 11490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) aura::TestScreen* test_screen() { return helper_->test_screen(); } 11590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 11690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void WaitForDraw() { 117a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) helper_->host()->compositor()->ScheduleDraw(); 118a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::DrawWaiterForTest::Wait(helper_->host()->compositor()); 11990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 12090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 12190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void SetupTestWindow(const gfx::Rect& window_bounds) { 12290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) delegate_.reset(new TestPaintingWindowDelegate(window_bounds.size())); 12390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) test_window_.reset(aura::test::CreateTestWindowWithDelegate( 12490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) delegate_.get(), 0, window_bounds, root_window())); 12590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 12690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 12790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Image GrabSnapshotForTestWindow() { 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Rect source_rect(test_window_->bounds().size()); 129f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) aura::Window::ConvertRectToTarget( 130f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) test_window(), root_window(), &source_rect); 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_refptr<base::TestSimpleTaskRunner> task_runner( 1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new base::TestSimpleTaskRunner()); 1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_refptr<SnapshotHolder> holder(new SnapshotHolder); 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::GrabWindowSnapshotAsync( 136f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) root_window(), 1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) source_rect, 1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) task_runner, 1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&SnapshotHolder::SnapshotCallback, holder)); 1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Wait for copy response. 1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WaitForDraw(); 1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Run internal snapshot callback to scale/rotate response image. 1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) task_runner->RunUntilIdle(); 1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Run SnapshotHolder callback. 1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) helper_->RunAllPendingInMessageLoop(); 1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (holder->completed()) 1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return holder->image(); 1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Callback never called. 1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NOTREACHED(); 1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return gfx::Image(); 15490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 15590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 15690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private: 1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class SnapshotHolder : public base::RefCountedThreadSafe<SnapshotHolder> { 1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SnapshotHolder() : completed_(false) {} 1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void SnapshotCallback(scoped_refptr<base::RefCountedBytes> png_data) { 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK(!completed_); 1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) image_ = gfx::Image::CreateFrom1xPNGBytes(&(png_data->data()[0]), 1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) png_data->size()); 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) completed_ = true; 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool completed() const { 1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return completed_; 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Image& image() const { return image_; } 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) friend class base::RefCountedThreadSafe<SnapshotHolder>; 1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual ~SnapshotHolder() {} 1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Image image_; 1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool completed_; 1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 18190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<aura::test::AuraTestHelper> helper_; 18290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<aura::Window> test_window_; 18390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<TestPaintingWindowDelegate> delegate_; 18490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) std::vector<unsigned char> png_representation_; 18590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 18690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(SnapshotAuraTest); 18790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 18890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 18990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(SnapshotAuraTest, FullScreenWindow) { 19090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SetupTestWindow(root_window()->bounds()); 19190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) WaitForDraw(); 19290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 19390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Image snapshot = GrabSnapshotForTestWindow(); 19490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(test_window()->bounds().size().ToString(), 19590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) snapshot.Size().ToString()); 19690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(0u, GetFailedPixelsCount(snapshot)); 19790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 19890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 19990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(SnapshotAuraTest, PartialBounds) { 20090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Rect test_bounds(100, 100, 300, 200); 20190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SetupTestWindow(test_bounds); 20290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) WaitForDraw(); 20390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 20490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Image snapshot = GrabSnapshotForTestWindow(); 2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(test_bounds.size().ToString(), snapshot.Size().ToString()); 20690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(0u, GetFailedPixelsCount(snapshot)); 20790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 20890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 20990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(SnapshotAuraTest, Rotated) { 21090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) test_screen()->SetDisplayRotation(gfx::Display::ROTATE_90); 21190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 21290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Rect test_bounds(100, 100, 300, 200); 21390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SetupTestWindow(test_bounds); 21490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) WaitForDraw(); 21590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 21690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Image snapshot = GrabSnapshotForTestWindow(); 2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(test_bounds.size().ToString(), snapshot.Size().ToString()); 21890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(0u, GetFailedPixelsCount(snapshot)); 21990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 22090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 22190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(SnapshotAuraTest, UIScale) { 22290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const float kUIScale = 1.25f; 22390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) test_screen()->SetUIScale(kUIScale); 22490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 22590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Rect test_bounds(100, 100, 300, 200); 22690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SetupTestWindow(test_bounds); 22790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) WaitForDraw(); 22890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 22990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Snapshot always captures the physical pixels. 23090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::SizeF snapshot_size(test_bounds.size()); 23190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 23290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Image snapshot = GrabSnapshotForTestWindow(); 23390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), 23490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) snapshot.Size().ToString()); 23590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(0u, GetFailedPixelsCount(snapshot)); 23690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 23790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 23890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(SnapshotAuraTest, DeviceScaleFactor) { 23990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) test_screen()->SetDeviceScaleFactor(2.0f); 24090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 24190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Rect test_bounds(100, 100, 150, 100); 24290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SetupTestWindow(test_bounds); 24390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) WaitForDraw(); 24490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 24590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Snapshot always captures the physical pixels. 24690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::SizeF snapshot_size(test_bounds.size()); 24790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) snapshot_size.Scale(2.0f); 24890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 24990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Image snapshot = GrabSnapshotForTestWindow(); 25090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), 25190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) snapshot.Size().ToString()); 2525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2)); 25390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 25490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 25590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(SnapshotAuraTest, RotateAndUIScale) { 25690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const float kUIScale = 1.25f; 25790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) test_screen()->SetUIScale(kUIScale); 25890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) test_screen()->SetDisplayRotation(gfx::Display::ROTATE_90); 25990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 26090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Rect test_bounds(100, 100, 300, 200); 26190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SetupTestWindow(test_bounds); 26290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) WaitForDraw(); 26390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 26490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Snapshot always captures the physical pixels. 26590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::SizeF snapshot_size(test_bounds.size()); 26690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 26790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Image snapshot = GrabSnapshotForTestWindow(); 26890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), 26990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) snapshot.Size().ToString()); 27090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(0u, GetFailedPixelsCount(snapshot)); 27190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 27290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 27390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(SnapshotAuraTest, RotateAndUIScaleAndScaleFactor) { 27490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) test_screen()->SetDeviceScaleFactor(2.0f); 27590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const float kUIScale = 1.25f; 27690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) test_screen()->SetUIScale(kUIScale); 27790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) test_screen()->SetDisplayRotation(gfx::Display::ROTATE_90); 27890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 27990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Rect test_bounds(20, 30, 150, 100); 28090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SetupTestWindow(test_bounds); 28190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) WaitForDraw(); 28290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 28390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Snapshot always captures the physical pixels. 28490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::SizeF snapshot_size(test_bounds.size()); 2855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) snapshot_size.Scale(2.0f); 28690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 28790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Image snapshot = GrabSnapshotForTestWindow(); 28890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), 28990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) snapshot.Size().ToString()); 2905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2)); 29190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 29290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 29390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace ui 294