Commit 7cd14fa5 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Turn on Find in Page iFrame feature flag by default

Now that FindinPageController's completionBlocks don't get executed,
use a TestFindInPageResponseDelegate. Also removes detachFromWebState
call because it actually breaks things by nulling out the webstate before
it is destroyed.

Bug: 919685, 996324
Change-Id: I503c9452d5ee9120aec0c9c1b79fd91379996965
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1749306Reviewed-by: default avatarYi Su <mrsuyi@chromium.org>
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691660}
parent f922aaa2
...@@ -9,4 +9,4 @@ ...@@ -9,4 +9,4 @@
#endif #endif
const base::Feature kFindInPageiFrame{"FindInPageiFrame", const base::Feature kFindInPageiFrame{"FindInPageiFrame",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_ENABLED_BY_DEFAULT};
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
#import "ios/chrome/browser/find_in_page/find_in_page_controller.h" #import "ios/chrome/browser/find_in_page/find_in_page_controller.h"
#import "base/mac/foundation_util.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#include "components/ukm/test_ukm_recorder.h" #include "components/ukm/test_ukm_recorder.h"
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#import "ios/chrome/browser/find_in_page/find_in_page_model.h" #import "ios/chrome/browser/find_in_page/find_in_page_model.h"
#import "ios/chrome/browser/find_in_page/find_in_page_response_delegate.h"
#include "ios/chrome/browser/metrics/ukm_url_recorder.h" #include "ios/chrome/browser/metrics/ukm_url_recorder.h"
#import "ios/chrome/browser/web/chrome_web_client.h" #import "ios/chrome/browser/web/chrome_web_client.h"
#import "ios/chrome/browser/web/chrome_web_test.h" #import "ios/chrome/browser/web/chrome_web_test.h"
...@@ -20,6 +22,17 @@ ...@@ -20,6 +22,17 @@
using base::test::ios::kWaitForJSCompletionTimeout; using base::test::ios::kWaitForJSCompletionTimeout;
using base::test::ios::WaitUntilConditionOrTimeout; using base::test::ios::WaitUntilConditionOrTimeout;
@interface TestFindInPageResponseDelegate
: NSObject <FindInPageResponseDelegate>
@property(nonatomic, strong) FindInPageModel* model;
@end
@implementation TestFindInPageResponseDelegate
- (void)findDidFinishWithUpdatedModel:(FindInPageModel*)model {
self.model = model;
}
@end
namespace { namespace {
const char kFindInPageUkmSearchMatchesEvent[] = "IOS.FindInPageSearchMatches"; const char kFindInPageUkmSearchMatchesEvent[] = "IOS.FindInPageSearchMatches";
...@@ -35,16 +48,18 @@ class FindInPageControllerTest : public ChromeWebTest { ...@@ -35,16 +48,18 @@ class FindInPageControllerTest : public ChromeWebTest {
ChromeWebTest::SetUp(); ChromeWebTest::SetUp();
find_in_page_controller_ = find_in_page_controller_ =
[[FindInPageController alloc] initWithWebState:web_state()]; [[FindInPageController alloc] initWithWebState:web_state()];
delegate_ = [[TestFindInPageResponseDelegate alloc] init];
find_in_page_controller_.responseDelegate = delegate_;
ukm::InitializeSourceUrlRecorderForWebState(web_state()); ukm::InitializeSourceUrlRecorderForWebState(web_state());
} }
void TearDown() override { void TearDown() override {
[find_in_page_controller_ detachFromWebState];
test_ukm_recorder_.Purge(); test_ukm_recorder_.Purge();
ChromeWebTest::TearDown(); ChromeWebTest::TearDown();
} }
FindInPageController* find_in_page_controller_ = nil; FindInPageController* find_in_page_controller_ = nil;
TestFindInPageResponseDelegate* delegate_;
ukm::TestAutoSetUkmRecorder test_ukm_recorder_; ukm::TestAutoSetUkmRecorder test_ukm_recorder_;
}; };
...@@ -53,14 +68,12 @@ class FindInPageControllerTest : public ChromeWebTest { ...@@ -53,14 +68,12 @@ class FindInPageControllerTest : public ChromeWebTest {
TEST_F(FindInPageControllerTest, VerifyUKMLoggedTrue) { TEST_F(FindInPageControllerTest, VerifyUKMLoggedTrue) {
test_ukm_recorder_.Purge(); test_ukm_recorder_.Purge();
LoadHtml(@"<html><p>some string</p></html>"); LoadHtml(@"<html><p>some string</p></html>");
__block bool completion_handler_finished = false;
[find_in_page_controller_ findStringInPage:@"some string" [find_in_page_controller_ findStringInPage:@"some string"
completionHandler:^{ completionHandler:^{
completion_handler_finished = true;
}]; }];
ASSERT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{ ASSERT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
return completion_handler_finished; return delegate_.model != nil;
})); }));
// Single true entry should be recorded for the interaction above. // Single true entry should be recorded for the interaction above.
const auto& entries = const auto& entries =
...@@ -76,14 +89,12 @@ TEST_F(FindInPageControllerTest, VerifyUKMLoggedTrue) { ...@@ -76,14 +89,12 @@ TEST_F(FindInPageControllerTest, VerifyUKMLoggedTrue) {
TEST_F(FindInPageControllerTest, VerifyUKMLoggedFalse) { TEST_F(FindInPageControllerTest, VerifyUKMLoggedFalse) {
test_ukm_recorder_.Purge(); test_ukm_recorder_.Purge();
LoadHtml(@"<html><p>some string</p></html>"); LoadHtml(@"<html><p>some string</p></html>");
__block bool completion_handler_finished = false;
[find_in_page_controller_ findStringInPage:@"nothing" [find_in_page_controller_ findStringInPage:@"nothing"
completionHandler:^{ completionHandler:^{
completion_handler_finished = true;
}]; }];
ASSERT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{ ASSERT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
return completion_handler_finished; return delegate_.model != nil;
})); }));
// Single false entry should be recorded for the interaction above. // Single false entry should be recorded for the interaction above.
const auto& entries = const auto& entries =
......
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