net: Remove code for session cookie deletion experiment.
[chromium-blink-merge.git] / ios / web / browsing_data_partition_impl_unittest.mm
blob8180cd7606979a5512b09fb198f16aca7a966704
1 // Copyright 2015 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.
5 #import "ios/web/browsing_data_partition_impl.h"
7 #include "base/ios/ios_util.h"
8 #include "base/memory/scoped_ptr.h"
9 #import "base/test/ios/wait_util.h"
10 #include "ios/web/public/active_state_manager.h"
11 #include "ios/web/public/browser_state.h"
12 #import "ios/web/public/crw_browsing_data_store.h"
13 #include "ios/web/public/test/test_browser_state.h"
14 #include "ios/web/public/test/test_web_thread_bundle.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/platform_test.h"
18 namespace web {
19 namespace {
21 class BrowsingDataPartitionImplTest : public PlatformTest {
22  protected:
23   void SetUp() override {
24     PlatformTest::SetUp();
25     browser_state_.reset(new TestBrowserState());
26     BrowserState::GetActiveStateManager(browser_state_.get())->SetActive(true);
27   }
28   void TearDown() override {
29     // The BrowserState needs to be destroyed first so that it is outlived by
30     // the WebThreadBundle.
31     BrowserState::GetActiveStateManager(browser_state_.get())->SetActive(false);
32     base::test::ios::WaitUntilCondition(^bool {
33       return BrowsingDataPartition::IsSynchronized();
34     });
35     browser_state_.reset();
36     PlatformTest::TearDown();
37   }
39   // The BrowserState used for testing purposes.
40   scoped_ptr<BrowserState> browser_state_;
42  private:
43   // Used to create TestWebThreads.
44   TestWebThreadBundle thread_bundle_;
47 }  // namespace
49 // Tests that a BrowsingDataPartitionImplTest is succesfully created with a
50 // BrowserState. And that it returns a non-nil BrowsingDataStore.
51 TEST_F(BrowsingDataPartitionImplTest, CreationAndBrowsingDataStore) {
52   if (!base::ios::IsRunningOnIOS8OrLater()) {
53     return;
54   }
56   BrowsingDataPartition* browsing_data_partition =
57       BrowserState::GetBrowsingDataPartition(browser_state_.get());
58   ASSERT_TRUE(browsing_data_partition);
60   EXPECT_TRUE(browsing_data_partition->GetBrowsingDataStore());
63 // Tests that a BrowsingDataPartitionImplTest successfully handles the case when
64 // multiple BrowserStates are made active/inactive.
65 TEST_F(BrowsingDataPartitionImplTest, ManyBrowserStates) {
66   if (!base::ios::IsRunningOnIOS8OrLater()) {
67     return;
68   }
70   scoped_ptr<BrowserState> browser_state_1(new TestBrowserState);
71   scoped_ptr<BrowserState> browser_state_2(new TestBrowserState);
73   // Create a BrowsingDataPartition associated with each of the BrowserStates.
74   ASSERT_TRUE(BrowserState::GetBrowsingDataPartition(browser_state_.get()));
75   ASSERT_TRUE(BrowserState::GetBrowsingDataPartition(browser_state_1.get()));
76   ASSERT_TRUE(BrowserState::GetBrowsingDataPartition(browser_state_2.get()));
78   ASSERT_TRUE(BrowsingDataPartition::IsSynchronized());
79   BrowserState::GetActiveStateManager(browser_state_.get())->SetActive(false);
81   BrowserState::GetActiveStateManager(browser_state_1.get())->SetActive(true);
82   BrowserState::GetActiveStateManager(browser_state_1.get())->SetActive(false);
84   BrowserState::GetActiveStateManager(browser_state_2.get())->SetActive(true);
85   BrowserState::GetActiveStateManager(browser_state_2.get())->SetActive(false);
86   // Test an edge case where a |makeActive:| call is enqueued in the same
87   // runloop as when the associated ActiveStateManager's active state is
88   // changed.
89   CRWBrowsingDataStore* store =
90       BrowserState::GetBrowsingDataPartition(browser_state_2.get())
91           ->GetBrowsingDataStore();
92   [store makeActiveWithCompletionHandler:nil];
94   EXPECT_FALSE(BrowsingDataPartition::IsSynchronized());
95   base::test::ios::WaitUntilCondition(^bool() {
96     return BrowsingDataPartition::IsSynchronized();
97   });
100 }  // namespace web