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

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:100px; "
124 "height:100px;'></div></html>");
125 __block bool snapshot_complete = false;
126 [[[UIApplication sharedApplication] keyWindow]
127 addSubview:web_state()->GetView()];
128 base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.1));
Eugene But (OOO till 7-30) 2017/06/22 19:34:14 nit: Could you please explain in the comments why
edchin 2017/06/23 19:03:10 Done.
129 web_state()->TakeSnapshot(base::BindBlockArc(^(const gfx::Image& snapshot) {
130 ASSERT_FALSE(snapshot.IsEmpty());
131 CGSize view_size = web_state()->GetView().bounds.size;
132 EXPECT_EQ(snapshot.Width(), view_size.width);
133 EXPECT_EQ(snapshot.Height(), view_size.height);
134 gfx::test::CheckColors(gfx::test::GetPlatformImageColor(
135 gfx::test::ToPlatformType(snapshot), 50, 50),
136 SK_ColorRED);
137 gfx::test::CheckColors(gfx::test::GetPlatformImageColor(
138 gfx::test::ToPlatformType(snapshot), 200, 200),
Eugene But (OOO till 7-30) 2017/06/22 20:09:37 Sorry, for not asking earlier. I assume this works
edchin 2017/06/23 19:03:10 This worked fine. But now there's an even better s
139 SK_ColorWHITE);
140 snapshot_complete = true;
141 }));
142 WaitForCondition(^{
143 return snapshot_complete;
144 });
145 }
146
115 } // namespace web 147 } // 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