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

Side by Side Diff: ios/web/web_state/web_state_unittest.mm

Issue 2945213002: [ios] Snapshot for WebState (Closed)
Patch Set: Address comments Created 3 years, 6 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 | « ios/web/web_state/web_state_impl.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #import "ios/web/public/web_state/web_state.h" 5 #import "ios/web/public/web_state/web_state.h"
6 6
7 #import <UIKit/UIKit.h>
8
7 #include "base/mac/bind_objc_block.h" 9 #include "base/mac/bind_objc_block.h"
8 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/test/ios/wait_util.h"
9 #include "base/values.h" 12 #include "base/values.h"
10 #import "ios/web/public/navigation_manager.h" 13 #import "ios/web/public/navigation_manager.h"
11 #import "ios/web/public/test/web_test_with_web_state.h" 14 #import "ios/web/public/test/web_test_with_web_state.h"
15 #include "ui/gfx/image/image.h"
16 #include "ui/gfx/image/image_unittest_util.h"
12 17
13 #if !defined(__has_feature) || !__has_feature(objc_arc) 18 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support." 19 #error "This file requires ARC support."
15 #endif 20 #endif
16 21
17 namespace web { 22 namespace web {
18 23
19 // Test fixture for web::WebTest class. 24 // Test fixture for web::WebTest class.
20 typedef web::WebTestWithWebState WebStateTest; 25 typedef web::WebTestWithWebState WebStateTest;
21 26
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 ASSERT_FALSE(navigation_manager->GetLastCommittedItem()); 110 ASSERT_FALSE(navigation_manager->GetLastCommittedItem());
106 111
107 navigation_manager->Reload(web::ReloadType::ORIGINAL_REQUEST_URL, 112 navigation_manager->Reload(web::ReloadType::ORIGINAL_REQUEST_URL,
108 false /* check_for_repost */); 113 false /* check_for_repost */);
109 114
110 ASSERT_FALSE(navigation_manager->GetTransientItem()); 115 ASSERT_FALSE(navigation_manager->GetTransientItem());
111 ASSERT_FALSE(navigation_manager->GetPendingItem()); 116 ASSERT_FALSE(navigation_manager->GetPendingItem());
112 ASSERT_FALSE(navigation_manager->GetLastCommittedItem()); 117 ASSERT_FALSE(navigation_manager->GetLastCommittedItem());
113 } 118 }
114 119
120 // Tests that the snapshot method returns an image of a rendered html page.
121 TEST_F(WebStateTest, Snapshot) {
122 LoadHtml(
123 "<html><div style='background-color:#FF0000; width:50%; "
124 "height:100%;'></div></html>");
125 __block bool snapshot_complete = false;
126 [[[UIApplication sharedApplication] keyWindow]
127 addSubview:web_state()->GetView()];
128 // The subview is added but not immediately painted, so a small delay is
129 // necessary.
130 base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.1));
131 CGSize target_size = CGSizeMake(100.0f, 100.0f);
132 web_state()->TakeSnapshot(
133 base::BindBlockArc(^(const gfx::Image& snapshot) {
134 ASSERT_FALSE(snapshot.IsEmpty());
135 EXPECT_EQ(snapshot.Width(), target_size.width);
136 EXPECT_EQ(snapshot.Height(), target_size.height);
137 // Test a pixel on the left (red) side.
138 gfx::test::CheckColors(gfx::test::GetPlatformImageColor(
139 gfx::test::ToPlatformType(snapshot), 45, 50),
140 SK_ColorRED);
141 // Test a pixel on the right (white) side.
142 gfx::test::CheckColors(gfx::test::GetPlatformImageColor(
143 gfx::test::ToPlatformType(snapshot), 55, 50),
144 SK_ColorWHITE);
145 snapshot_complete = true;
146 }),
147 target_size);
148 WaitForCondition(^{
149 return snapshot_complete;
150 });
151 }
152
115 } // namespace web 153 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/web_state/web_state_impl.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698