Commit e6c32ed5 authored by rohitrao's avatar rohitrao Committed by Commit bot

[ios] Simplifies the Find In Page JS unittest.

This test does not need a full FindInPageController, so that is removed from the
test fixture.  Additionally, the find in page unittest files are moved from
ios/chrome/browser/web to ios/chrome/browser/find_in_page.

BUG=691073

Review-Url: https://codereview.chromium.org/2711513002
Cr-Commit-Position: refs/heads/master@{#453241}
parent 3dc27d31
...@@ -41,8 +41,27 @@ source_set("unit_tests") { ...@@ -41,8 +41,27 @@ source_set("unit_tests") {
] ]
deps = [ deps = [
":find_in_page", ":find_in_page",
":unit_tests_nonarc",
"//base", "//base",
"//ios/web", "//ios/web",
"//ios/web:test_support", "//ios/web:test_support",
"//testing/gtest",
]
}
source_set("unit_tests_nonarc") {
testonly = true
sources = [
"find_in_page_js_unittest.mm",
"js_findinpage_manager_unittest.mm",
]
deps = [
":find_in_page",
"//base",
"//base/test:test_support",
"//ios/chrome/browser/web:test_support",
"//ios/web",
"//ios/web:test_support",
"//testing/gtest",
] ]
} }
...@@ -4,16 +4,19 @@ ...@@ -4,16 +4,19 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "ios/chrome/browser/find_in_page/find_in_page_controller.h" #import "ios/chrome/browser/find_in_page/find_in_page_model.h"
#import "ios/chrome/browser/find_in_page/js_findinpage_manager.h"
#import "ios/chrome/browser/web/chrome_web_test.h" #import "ios/chrome/browser/web/chrome_web_test.h"
#import "ios/web/public/web_state/crw_web_view_proxy.h"
#import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
#import "ios/web/public/web_state/web_state.h" #import "ios/web/public/web_state/web_state.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h" #include "testing/gtest_mac.h"
#import "third_party/ocmock/OCMock/OCMock.h"
// Unit tests for the models/resources/find_in_page.js JavaScript file. // Unit tests for the find_in_page.js JavaScript file.
namespace { namespace {
...@@ -63,7 +66,11 @@ class FindInPageJsTest : public ChromeWebTest { ...@@ -63,7 +66,11 @@ class FindInPageJsTest : public ChromeWebTest {
// Loads the given HTML, then loads the |findInPage| JavaScript. // Loads the given HTML, then loads the |findInPage| JavaScript.
void LoadHtml(NSString* html) { void LoadHtml(NSString* html) {
ChromeWebTest::LoadHtml(html); ChromeWebTest::LoadHtml(html);
[findInPageController_ initFindInPage];
// Inject and initialize the find in page javascript.
[findInPageJsManager_ inject];
CGRect frame = [web_state()->GetWebViewProxy() bounds];
[findInPageJsManager_ setWidth:frame.size.width height:frame.size.height];
} }
// Runs the given JavaScript and asserts that the result matches the given // Runs the given JavaScript and asserts that the result matches the given
...@@ -94,15 +101,15 @@ class FindInPageJsTest : public ChromeWebTest { ...@@ -94,15 +101,15 @@ class FindInPageJsTest : public ChromeWebTest {
void SetUp() override { void SetUp() override {
ChromeWebTest::SetUp(); ChromeWebTest::SetUp();
mockDelegate_.reset([[OCMockObject findInPageModel_.reset([[FindInPageModel alloc] init]);
niceMockForProtocol:@protocol(FindInPageControllerDelegate)] retain]); findInPageJsManager_.reset([base::mac::ObjCCastStrict<JsFindinpageManager>(
findInPageController_.reset([[FindInPageController alloc] [web_state()->GetJSInjectionReceiver()
initWithWebState:web_state() instanceOfClass:[JsFindinpageManager class]]) retain]);
delegate:mockDelegate_]); findInPageJsManager_.get().findInPageModel = findInPageModel_;
} }
base::scoped_nsobject<FindInPageController> findInPageController_; base::scoped_nsobject<FindInPageModel> findInPageModel_;
base::scoped_nsobject<id> mockDelegate_; base::scoped_nsobject<JsFindinpageManager> findInPageJsManager_;
}; };
// Performs a search, then calls |incrementIndex| to loop through the // Performs a search, then calls |incrementIndex| to loop through the
......
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/chrome/browser/find_in_page/js_findinpage_manager.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#import "ios/chrome/browser/find_in_page/js_findinpage_manager.h"
#import "ios/chrome/browser/web/chrome_web_test.h" #import "ios/chrome/browser/web/chrome_web_test.h"
#import "ios/web/public/web_state/js/crw_js_injection_receiver.h" #import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
#import "ios/web/public/web_state/web_state.h" #import "ios/web/public/web_state/web_state.h"
......
...@@ -225,8 +225,6 @@ source_set("unit_tests_internal") { ...@@ -225,8 +225,6 @@ source_set("unit_tests_internal") {
"chrome_web_client_unittest.mm", "chrome_web_client_unittest.mm",
"error_page_generator_unittest.mm", "error_page_generator_unittest.mm",
"external_app_launcher_unittest.mm", "external_app_launcher_unittest.mm",
"find_in_page_js_unittest.mm",
"js_findinpage_manager_unittest.mm",
] ]
deps = [ deps = [
":test_support", ":test_support",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment