OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/web/tab_id_tab_helper.h" |
| 6 |
| 7 #import "ios/web/public/test/fakes/test_web_state.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #import "testing/gtest_mac.h" |
| 10 #include "testing/platform_test.h" |
| 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." |
| 14 #endif |
| 15 |
| 16 // Test fixture for TabIdTabHelper class. |
| 17 class TabIdTabHelperTest : public PlatformTest { |
| 18 protected: |
| 19 web::TestWebState first_web_state_; |
| 20 web::TestWebState second_web_state_; |
| 21 }; |
| 22 |
| 23 // Tests that a tab ID is returned for a WebState, and tab ID's are different |
| 24 // for different WebStates. |
| 25 TEST_F(TabIdTabHelperTest, UniqueIdentifiers) { |
| 26 TabIdTabHelper::CreateForWebState(&first_web_state_); |
| 27 TabIdTabHelper::CreateForWebState(&second_web_state_); |
| 28 |
| 29 const NSString* first_tab_id = |
| 30 TabIdTabHelper::FromWebState(&first_web_state_)->tab_id(); |
| 31 const NSString* second_tab_id = |
| 32 TabIdTabHelper::FromWebState(&second_web_state_)->tab_id(); |
| 33 |
| 34 EXPECT_GT([first_tab_id length], 0U); |
| 35 EXPECT_GT([second_tab_id length], 0U); |
| 36 EXPECT_NSNE(first_tab_id, second_tab_id); |
| 37 } |
| 38 |
| 39 // Tests that a tab ID is stable across successive calls. |
| 40 TEST_F(TabIdTabHelperTest, StableAcrossCalls) { |
| 41 TabIdTabHelper::CreateForWebState(&first_web_state_); |
| 42 TabIdTabHelper* tab_helper = TabIdTabHelper::FromWebState(&first_web_state_); |
| 43 |
| 44 const NSString* first_call_id = tab_helper->tab_id(); |
| 45 const NSString* second_call_id = tab_helper->tab_id(); |
| 46 |
| 47 EXPECT_NSEQ(first_call_id, second_call_id); |
| 48 } |
| 49 |
| 50 // Tests serialization of a tab ID. |
| 51 TEST_F(TabIdTabHelperTest, Serialization) { |
| 52 TabIdTabHelper::CreateForWebState(&first_web_state_); |
| 53 TabIdTabHelper* first_tab_helper = |
| 54 TabIdTabHelper::FromWebState(&first_web_state_); |
| 55 const NSString* first_call_id = first_tab_helper->tab_id(); |
| 56 |
| 57 first_tab_helper->RemoveFromWebState(&first_web_state_); |
| 58 |
| 59 TabIdTabHelper::CreateForWebState(&first_web_state_); |
| 60 TabIdTabHelper* second_tab_helper = |
| 61 TabIdTabHelper::FromWebState(&first_web_state_); |
| 62 const NSString* second_call_id = second_tab_helper->tab_id(); |
| 63 |
| 64 EXPECT_NSEQ(first_call_id, second_call_id); |
| 65 } |
OLD | NEW |