Chromium Code Reviews| Index: ios/web/web_state/web_state_unittest.mm |
| diff --git a/ios/web/web_state/web_state_unittest.mm b/ios/web/web_state/web_state_unittest.mm |
| index 35c165c2e97920b0a1148b38be887504cdee26f9..73310a39f8916d31a287e6afc423e37546f0ac3a 100644 |
| --- a/ios/web/web_state/web_state_unittest.mm |
| +++ b/ios/web/web_state/web_state_unittest.mm |
| @@ -4,11 +4,16 @@ |
| #import "ios/web/public/web_state/web_state.h" |
| +#import <UIKit/UIKit.h> |
| + |
| #include "base/mac/bind_objc_block.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/test/ios/wait_util.h" |
| #include "base/values.h" |
| #import "ios/web/public/navigation_manager.h" |
| #import "ios/web/public/test/web_test_with_web_state.h" |
| +#include "ui/gfx/image/image.h" |
| +#include "ui/gfx/image/image_unittest_util.h" |
| #if !defined(__has_feature) || !__has_feature(objc_arc) |
| #error "This file requires ARC support." |
| @@ -112,4 +117,31 @@ TEST_F(WebStateTest, ReloadWithOriginalTypeWithEmptyNavigationManager) { |
| ASSERT_FALSE(navigation_manager->GetLastCommittedItem()); |
| } |
| +// Tests that the snapshot method returns an image of a rendered html page. |
| +TEST_F(WebStateTest, Snapshot) { |
| + LoadHtml( |
| + "<html><div style='background-color:#FF0000; width:100px; " |
| + "height:100px;'></div></html>"); |
| + __block bool snapshot_complete = false; |
| + [[[UIApplication sharedApplication] keyWindow] |
| + addSubview:web_state()->GetView()]; |
| + 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.
|
| + web_state()->TakeSnapshot(base::BindBlockArc(^(const gfx::Image& snapshot) { |
| + ASSERT_FALSE(snapshot.IsEmpty()); |
| + CGSize view_size = web_state()->GetView().bounds.size; |
| + EXPECT_EQ(snapshot.Width(), view_size.width); |
| + EXPECT_EQ(snapshot.Height(), view_size.height); |
| + gfx::test::CheckColors(gfx::test::GetPlatformImageColor( |
| + gfx::test::ToPlatformType(snapshot), 50, 50), |
| + SK_ColorRED); |
| + gfx::test::CheckColors(gfx::test::GetPlatformImageColor( |
| + 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
|
| + SK_ColorWHITE); |
| + snapshot_complete = true; |
| + })); |
| + WaitForCondition(^{ |
| + return snapshot_complete; |
| + }); |
| +} |
| + |
| } // namespace web |