Index: ios/chrome/browser/metrics/tab_usage_recorder_unittest.mm |
diff --git a/ios/chrome/browser/metrics/tab_usage_recorder_unittest.mm b/ios/chrome/browser/metrics/tab_usage_recorder_unittest.mm |
index ca0817bb3b7d0c7201b6f0f7c9e7959367255ad4..31672db7ce4483cc2514fefd37b40d67a4a9db8a 100644 |
--- a/ios/chrome/browser/metrics/tab_usage_recorder_unittest.mm |
+++ b/ios/chrome/browser/metrics/tab_usage_recorder_unittest.mm |
@@ -4,6 +4,7 @@ |
#include <memory> |
+#include "base/memory/ptr_util.h" |
#include "base/message_loop/message_loop.h" |
#include "base/metrics/histogram_samples.h" |
#include "base/stl_util.h" |
@@ -13,6 +14,8 @@ |
#import "ios/chrome/browser/metrics/tab_usage_recorder_delegate.h" |
#import "ios/chrome/browser/tabs/tab.h" |
#include "ios/testing/ocmock_complex_type_helper.h" |
+#import "ios/web/public/test/fakes/test_navigation_manager.h" |
+#import "ios/web/public/test/fakes/test_web_state.h" |
#include "ios/web/public/test/test_web_thread.h" |
#import "ios/web/web_state/ui/crw_web_controller.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -25,9 +28,16 @@ |
@interface TURTestTabMock : OCMockComplexTypeHelper { |
GURL _url; |
+ GURL _lastCommittedURL; |
+ GURL _visibleURL; |
+ web::TestWebState _webState; |
} |
@property(nonatomic, assign) const GURL& url; |
+@property(nonatomic, assign) const GURL& lastCommittedURL; |
+@property(nonatomic, assign) const GURL& visibleURL; |
+@property(nonatomic, readonly) web::WebState* webState; |
+ |
@end |
@implementation TURTestTabMock |
@@ -37,6 +47,25 @@ @implementation TURTestTabMock |
- (void)setUrl:(const GURL&)url { |
_url = url; |
} |
+- (const GURL&)lastCommittedURL { |
+ return _lastCommittedURL; |
+} |
+- (void)setLastCommittedURL:(const GURL&)lastCommittedURL { |
+ _lastCommittedURL = lastCommittedURL; |
+} |
+- (const GURL&)visibleURL { |
+ return _visibleURL; |
+} |
+- (void)setVisibleURL:(const GURL&)visibleURL { |
+ _visibleURL = visibleURL; |
+} |
+- (web::WebState*)webState { |
+ if (!_webState.GetNavigationManager()) { |
+ _webState.SetNavigationManager( |
+ base::MakeUnique<web::TestNavigationManager>()); |
+ } |
+ return &_webState; |
+} |
@end |
// A mock TabUsageRecorderDelegate which allows the unit tests to control |
@@ -106,6 +135,8 @@ id MockTab(bool inMemory) { |
[[[tab_mock stub] andReturn:web_controller_mock] webController]; |
[[[tab_mock stub] andReturnBool:false] isPrerenderTab]; |
[tab_mock setUrl:webUrl_]; |
+ [tab_mock setLastCommittedURL:webUrl_]; |
+ [tab_mock setVisibleURL:webUrl_]; |
[[[web_controller_mock stub] andReturnBool:inMemory] isViewAlive]; |
[[web_controller_mock stub] removeObserver:OCMOCK_ANY]; |
return tab_mock; |
@@ -173,7 +204,11 @@ id MockTab(bool inMemory) { |
id tab_mock_a = MockTab(true); |
id tab_mock_b = MockTab(false); |
[tab_mock_a setUrl:nativeUrl_]; |
+ [tab_mock_a setLastCommittedURL:nativeUrl_]; |
+ [tab_mock_a setVisibleURL:nativeUrl_]; |
[tab_mock_b setUrl:nativeUrl_]; |
+ [tab_mock_b setLastCommittedURL:nativeUrl_]; |
+ [tab_mock_b setVisibleURL:nativeUrl_]; |
// Call reload an arbitrary number of times. |
const int kNumReloads = 4; |