Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Unified Diff: ios/chrome/browser/web/tab_id_tab_helper_unittest.mm

Issue 2956483003: [ios] TabIdTabHelper (Closed)
Patch Set: Additional unit tests and other edits. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/web/tab_id_tab_helper.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/web/tab_id_tab_helper_unittest.mm
diff --git a/ios/chrome/browser/web/tab_id_tab_helper_unittest.mm b/ios/chrome/browser/web/tab_id_tab_helper_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..4709fc4a295220b66909999e5e1ca8f3b928d50b
--- /dev/null
+++ b/ios/chrome/browser/web/tab_id_tab_helper_unittest.mm
@@ -0,0 +1,65 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/web/tab_id_tab_helper.h"
+
+#import "ios/web/public/test/fakes/test_web_state.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#import "testing/gtest_mac.h"
+#include "testing/platform_test.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+// Test fixture for TabIdTabHelper class.
+class TabIdTabHelperTest : public PlatformTest {
+ protected:
+ web::TestWebState first_web_state_;
+ web::TestWebState second_web_state_;
+};
+
+// Tests that a tab ID is returned for a WebState, and tab ID's are different
+// for different WebStates.
+TEST_F(TabIdTabHelperTest, UniqueIdentifiers) {
+ TabIdTabHelper::CreateForWebState(&first_web_state_);
+ TabIdTabHelper::CreateForWebState(&second_web_state_);
+
+ const NSString* first_tab_id =
+ TabIdTabHelper::FromWebState(&first_web_state_)->tab_id();
+ const NSString* second_tab_id =
+ TabIdTabHelper::FromWebState(&second_web_state_)->tab_id();
+
+ EXPECT_GT([first_tab_id length], 0U);
+ EXPECT_GT([second_tab_id length], 0U);
+ EXPECT_NSNE(first_tab_id, second_tab_id);
+}
+
+// Tests that a tab ID is stable across successive calls.
+TEST_F(TabIdTabHelperTest, StableAcrossCalls) {
+ TabIdTabHelper::CreateForWebState(&first_web_state_);
+ TabIdTabHelper* tab_helper = TabIdTabHelper::FromWebState(&first_web_state_);
+
+ const NSString* first_call_id = tab_helper->tab_id();
+ const NSString* second_call_id = tab_helper->tab_id();
+
+ EXPECT_NSEQ(first_call_id, second_call_id);
+}
+
+// Tests serialization of a tab ID.
+TEST_F(TabIdTabHelperTest, Serialization) {
+ TabIdTabHelper::CreateForWebState(&first_web_state_);
+ TabIdTabHelper* first_tab_helper =
+ TabIdTabHelper::FromWebState(&first_web_state_);
+ const NSString* first_call_id = first_tab_helper->tab_id();
+
+ first_tab_helper->RemoveFromWebState(&first_web_state_);
+
+ TabIdTabHelper::CreateForWebState(&first_web_state_);
+ TabIdTabHelper* second_tab_helper =
+ TabIdTabHelper::FromWebState(&first_web_state_);
+ const NSString* second_call_id = second_tab_helper->tab_id();
+
+ EXPECT_NSEQ(first_call_id, second_call_id);
+}
« no previous file with comments | « ios/chrome/browser/web/tab_id_tab_helper.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698