summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/clear_on_exit_policy_unittest.cc
blob: d097febca2e45bc7f8cb0c6b2010912a8176df01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) 2012 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.

#include "testing/gtest/include/gtest/gtest.h"

#include "chrome/browser/net/clear_on_exit_policy.h"
#include "googleurl/src/gurl.h"
#include "webkit/quota/mock_special_storage_policy.h"


TEST(ClearOnExitPolicyTest, HasClearOnExitOrigins) {
  scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy =
      new quota::MockSpecialStoragePolicy;
  scoped_refptr<ClearOnExitPolicy> policy =
      new ClearOnExitPolicy(storage_policy.get());

  EXPECT_FALSE(policy->HasClearOnExitOrigins());

  storage_policy->AddSessionOnly(GURL("http://test.com/"));
  EXPECT_TRUE(policy->HasClearOnExitOrigins());
}

TEST(ClearOnExitPolicyTest, ShouldClearOriginOnExit) {
  scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy =
      new quota::MockSpecialStoragePolicy;
  storage_policy->AddSessionOnly(GURL("http://session.com/"));
  storage_policy->AddSessionOnly(GURL("https://secure.com/"));
  storage_policy->AddSessionOnly(GURL("http://protected.com/"));
  storage_policy->AddProtected(GURL("http://protected.com/"));

  scoped_refptr<ClearOnExitPolicy> policy =
      new ClearOnExitPolicy(storage_policy.get());

  EXPECT_TRUE(policy->ShouldClearOriginOnExit("session.com", false));
  EXPECT_FALSE(policy->ShouldClearOriginOnExit("session.com", true));

  EXPECT_FALSE(policy->ShouldClearOriginOnExit("secure.com", false));
  EXPECT_TRUE(policy->ShouldClearOriginOnExit("secure.com", true));

  EXPECT_FALSE(policy->ShouldClearOriginOnExit("protected.com", false));
  EXPECT_FALSE(policy->ShouldClearOriginOnExit("protected.com", true));

  EXPECT_FALSE(policy->ShouldClearOriginOnExit("other.com", false));
  EXPECT_FALSE(policy->ShouldClearOriginOnExit("other.com", true));
}