| 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..76b37f8e4df461b6079c7cc787498cc502df1a81 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,37 @@ 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:50%; "
|
| + "height:100%;'></div></html>");
|
| + __block bool snapshot_complete = false;
|
| + [[[UIApplication sharedApplication] keyWindow]
|
| + addSubview:web_state()->GetView()];
|
| + // The subview is added but not immediately painted, so a small delay is
|
| + // necessary.
|
| + base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.1));
|
| + CGSize target_size = CGSizeMake(100.0f, 100.0f);
|
| + web_state()->TakeSnapshot(
|
| + base::BindBlockArc(^(const gfx::Image& snapshot) {
|
| + ASSERT_FALSE(snapshot.IsEmpty());
|
| + EXPECT_EQ(snapshot.Width(), target_size.width);
|
| + EXPECT_EQ(snapshot.Height(), target_size.height);
|
| + // Test a pixel on the left (red) side.
|
| + gfx::test::CheckColors(gfx::test::GetPlatformImageColor(
|
| + gfx::test::ToPlatformType(snapshot), 45, 50),
|
| + SK_ColorRED);
|
| + // Test a pixel on the right (white) side.
|
| + gfx::test::CheckColors(gfx::test::GetPlatformImageColor(
|
| + gfx::test::ToPlatformType(snapshot), 55, 50),
|
| + SK_ColorWHITE);
|
| + snapshot_complete = true;
|
| + }),
|
| + target_size);
|
| + WaitForCondition(^{
|
| + return snapshot_complete;
|
| + });
|
| +}
|
| +
|
| } // namespace web
|
|
|