Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extension_tabs_module.h" | 5 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/extensions/extension_function_test_utils.h" | 14 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 15 #include "chrome/browser/extensions/extension_tabs_module_constants.h" | |
| 15 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
| 16 #include "chrome/browser/extensions/extension_tabs_module_constants.h" | 17 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 18 #include "chrome/browser/profiles/profile.h" | |
| 17 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
| 19 #include "chrome/test/base/in_process_browser_test.h" | 21 #include "chrome/test/base/in_process_browser_test.h" |
| 20 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| 21 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
| 22 | 24 |
| 23 using namespace extension_function_test_utils; | 25 using namespace extension_function_test_utils; |
| 24 | 26 |
| 25 namespace { | 27 namespace { |
| 26 | 28 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 update_tab_function->set_extension(empty_extension.get()); | 121 update_tab_function->set_extension(empty_extension.get()); |
| 120 // Without a callback the function will not generate a result. | 122 // Without a callback the function will not generate a result. |
| 121 update_tab_function->set_has_callback(true); | 123 update_tab_function->set_has_callback(true); |
| 122 | 124 |
| 123 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 125 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 124 update_tab_function.get(), | 126 update_tab_function.get(), |
| 125 "[null, {\"url\": \"neutrinos\"}]", | 127 "[null, {\"url\": \"neutrinos\"}]", |
| 126 browser())); | 128 browser())); |
| 127 EXPECT_EQ(base::Value::TYPE_NULL, result->GetType()); | 129 EXPECT_EQ(base::Value::TYPE_NULL, result->GetType()); |
| 128 } | 130 } |
| 131 | |
| 132 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, | |
| 133 DontCreateNormalWindowWhenIncognitoForced) { | |
| 134 static const char kArgsWithoutExplicitIncognitoParam[] = | |
| 135 "[{\"url\": \"about:blank\"}]"; | |
| 136 static const char kArgsWithExplicitIncognitoParam[] = | |
| 137 "[{\"url\": \"about:blank\", \"incognito\": false }]"; | |
| 138 // Force Incognito mode. | |
| 139 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), | |
| 140 IncognitoModePrefs::FORCED); | |
| 141 // Run without an explicit "incognito" param. | |
| 142 EXPECT_TRUE(MatchPattern( | |
| 143 RunFunctionAndReturnError( | |
| 144 new CreateWindowFunction(), | |
| 145 kArgsWithoutExplicitIncognitoParam, | |
|
Aaron Boodman
2011/10/25 08:35:09
In this case, shouldn't we default to incognito? S
rustema
2011/10/26 07:13:41
Makes sense. Done.
| |
| 146 browser()), | |
| 147 extension_tabs_module_constants::kIncognitoModeIsForced)); | |
| 148 | |
| 149 // Run with an explicit "incognito" param. | |
| 150 EXPECT_TRUE(MatchPattern( | |
| 151 RunFunctionAndReturnError( | |
| 152 new CreateWindowFunction(), | |
| 153 kArgsWithExplicitIncognitoParam, | |
| 154 browser()), | |
| 155 extension_tabs_module_constants::kIncognitoModeIsForced)); | |
| 156 | |
| 157 // Now try opening a normal window from incognito window. | |
| 158 Browser* incognito_browser = CreateIncognitoBrowser(); | |
| 159 // Run without an explicit "incognito" param. | |
| 160 EXPECT_TRUE(MatchPattern( | |
| 161 RunFunctionAndReturnError( | |
| 162 new CreateWindowFunction(), | |
| 163 kArgsWithoutExplicitIncognitoParam, | |
| 164 incognito_browser), | |
| 165 extension_tabs_module_constants::kIncognitoModeIsForced)); | |
| 166 | |
| 167 // Run with an explicit "incognito" param. | |
| 168 EXPECT_TRUE(MatchPattern( | |
| 169 RunFunctionAndReturnError( | |
| 170 new CreateWindowFunction(), | |
| 171 kArgsWithExplicitIncognitoParam, | |
| 172 incognito_browser), | |
| 173 extension_tabs_module_constants::kIncognitoModeIsForced)); | |
| 174 } | |
| 175 | |
| 176 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, | |
| 177 DontCreateIncognitoWindowWhenIncognitoDisabled) { | |
| 178 static const char kArgs[] = | |
| 179 "[{\"url\": \"about:blank\", \"incognito\": true }]"; | |
| 180 | |
| 181 Browser* incognito_browser = CreateIncognitoBrowser(); | |
| 182 // Disable Incognito mode. | |
| 183 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), | |
| 184 IncognitoModePrefs::DISABLED); | |
| 185 // Run in normal window. | |
| 186 EXPECT_TRUE(MatchPattern( | |
| 187 RunFunctionAndReturnError( | |
| 188 new CreateWindowFunction(), | |
| 189 kArgs, | |
| 190 browser()), | |
| 191 extension_tabs_module_constants::kIncognitoModeIsDisabled)); | |
| 192 | |
| 193 // Run in incognito window. | |
| 194 EXPECT_TRUE(MatchPattern( | |
| 195 RunFunctionAndReturnError( | |
| 196 new CreateWindowFunction(), | |
| 197 kArgs, | |
| 198 incognito_browser), | |
| 199 extension_tabs_module_constants::kIncognitoModeIsDisabled)); | |
| 200 } | |
| OLD | NEW |