summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser_unittest.cc
blob: e6a530e68a8b8a930247368d6ed35a7e434e61f1 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright (c) 2010 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 "chrome/browser/browser.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {

const struct NavigationScenario {
  bool pinned;
  const char* url;
  const char* referrer;
  PageTransition::Type transition;
  WindowOpenDisposition original_disposition;
  WindowOpenDisposition result_disposition;
} kNavigationScenarios[] = {
  // Disposition changes to new foreground.
  { true,
    "http://www.example.com",
    "http://www.google.com",
    PageTransition::LINK,
    CURRENT_TAB,
    NEW_FOREGROUND_TAB },
  // Also works with AUTO_BOOKMARK.
  { true,
    "http://www.example.com",
    "http://www.google.com",
    PageTransition::AUTO_BOOKMARK,
    CURRENT_TAB,
    NEW_FOREGROUND_TAB },
  // Also works with TYPED.
  { true,
    "http://www.example.com",
    "http://www.google.com",
    PageTransition::TYPED,
    CURRENT_TAB,
    NEW_FOREGROUND_TAB },
  // Also happens if the schemes differ.
  { true,
    "ftp://www.example.com",
    "http://www.example.com",
    PageTransition::LINK,
    CURRENT_TAB,
    NEW_FOREGROUND_TAB },
  // Don't choke on an empty referrer.
  { true,
    "ftp://www.example.com",
    "",
    PageTransition::LINK,
    CURRENT_TAB,
    NEW_FOREGROUND_TAB },
  // Unpinned tab - no change.
  { false,
    "http://www.example.com",
    "http://www.google.com",
    PageTransition::LINK,
    CURRENT_TAB,
    CURRENT_TAB },
  // Original disposition is not CURRENT_TAB - no change.
  { true,
    "http://www.example.com",
    "http://www.google.com",
    PageTransition::LINK,
    NEW_BACKGROUND_TAB,
    NEW_BACKGROUND_TAB },
  // Other PageTransition type - no change.
  { true,
    "http://www.example.com",
    "http://www.google.com",
    PageTransition::RELOAD,
    CURRENT_TAB,
    CURRENT_TAB },
  // Same domain and scheme - no change.
  { true,
    "http://www.google.com/reader",
    "http://www.google.com",
    PageTransition::LINK,
    CURRENT_TAB,
    CURRENT_TAB },
  // Switching between http and https - no change.
  { true,
    "https://www.example.com",
    "http://www.example.com",
    PageTransition::LINK,
    CURRENT_TAB,
    CURRENT_TAB },
  // Switching between https and http - no change.
  { true,
    "http://www.example.com",
    "https://www.example.com",
    PageTransition::LINK,
    CURRENT_TAB,
    CURRENT_TAB },
};

}  // namespace

TEST(BrowserTest, PinnedTabDisposition) {
  for (size_t i = 0; i < arraysize(kNavigationScenarios); ++i) {
    EXPECT_EQ(kNavigationScenarios[i].result_disposition,
              Browser::AdjustWindowOpenDispositionForTab(
                  kNavigationScenarios[i].pinned,
                  GURL(kNavigationScenarios[i].url),
                  GURL(kNavigationScenarios[i].referrer),
                  kNavigationScenarios[i].transition,
                  kNavigationScenarios[i].original_disposition)) << i;
  }
}