OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/extensions/extension_tab_util_delegate_chromeo s.h" | 5 #include "chrome/browser/chromeos/extensions/extension_tab_util_delegate_chromeo s.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "chromeos/login/login_state.h" | 9 #include "chromeos/login/login_state.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace extensions { | 12 namespace extensions { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 const char kWhitelistedId[] = "cbkkbcmdlboombapidmoeolnmdacpkch"; | |
17 // Use an extension ID that will never be whitelisted. | |
18 const char kNonWhitelistedId[] = "bogus"; | |
19 | |
16 const char kTestUrl[] = "http://www.foo.bar/baz?key=val"; | 20 const char kTestUrl[] = "http://www.foo.bar/baz?key=val"; |
17 const char kFilteredUrl[] = "http://www.foo.bar/"; | 21 const char kFilteredUrl[] = "http://www.foo.bar/"; |
18 | 22 |
19 } // namespace | 23 } // namespace |
20 | 24 |
21 class ExtensionTabUtilDelegateChromeOSTest : public testing::Test { | 25 class ExtensionTabUtilDelegateChromeOSTest : public testing::Test { |
22 protected: | 26 protected: |
23 void SetUp() override; | 27 void SetUp() override; |
24 | 28 |
25 ExtensionTabUtilDelegateChromeOS delegate_; | 29 ExtensionTabUtilDelegateChromeOS delegate_; |
26 api::tabs::Tab tab_; | 30 api::tabs::Tab tab_; |
27 }; | 31 }; |
28 | 32 |
29 void ExtensionTabUtilDelegateChromeOSTest::SetUp() { | 33 void ExtensionTabUtilDelegateChromeOSTest::SetUp() { |
30 tab_.url.reset(new std::string(kTestUrl)); | 34 tab_.url.reset(new std::string(kTestUrl)); |
31 } | 35 } |
32 | 36 |
33 TEST_F(ExtensionTabUtilDelegateChromeOSTest, NoFilteringOutsidePublicSession) { | 37 TEST_F(ExtensionTabUtilDelegateChromeOSTest, |
38 NoFilteringOutsidePublicSessionForWhitelisted) { | |
34 ASSERT_FALSE(chromeos::LoginState::IsInitialized()); | 39 ASSERT_FALSE(chromeos::LoginState::IsInitialized()); |
35 | 40 |
36 delegate_.ScrubTabForExtension(nullptr, nullptr, &tab_); | 41 delegate_.ScrubTabForExtension(kWhitelistedId, &tab_); |
37 EXPECT_EQ(kTestUrl, *tab_.url); | 42 EXPECT_EQ(kTestUrl, *tab_.url); |
38 } | 43 } |
39 | 44 |
40 TEST_F(ExtensionTabUtilDelegateChromeOSTest, ScrubURL) { | 45 TEST_F(ExtensionTabUtilDelegateChromeOSTest, |
46 NoFilteringOutsidePublicSessionForNonWhitelisted) { | |
47 ASSERT_FALSE(chromeos::LoginState::IsInitialized()); | |
48 | |
49 delegate_.ScrubTabForExtension(kNonWhitelistedId, &tab_); | |
50 EXPECT_EQ(kTestUrl, *tab_.url); | |
51 } | |
52 | |
53 TEST_F(ExtensionTabUtilDelegateChromeOSTest, | |
54 NoFilteringInsidePublicSessionForWhitelisted) { | |
41 // Set Public Session state. | 55 // Set Public Session state. |
42 chromeos::LoginState::Initialize(); | 56 chromeos::LoginState::Initialize(); |
43 chromeos::LoginState::Get()->SetLoggedInState( | 57 chromeos::LoginState::Get()->SetLoggedInState( |
44 chromeos::LoginState::LOGGED_IN_ACTIVE, | 58 chromeos::LoginState::LOGGED_IN_ACTIVE, |
Devlin
2017/05/03 15:14:15
drive-by: indentation looks off here.
| |
45 chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT); | 59 chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT); |
46 | 60 |
47 delegate_.ScrubTabForExtension(nullptr, nullptr, &tab_); | 61 delegate_.ScrubTabForExtension(kWhitelistedId, &tab_); |
62 EXPECT_EQ(kTestUrl, *tab_.url); | |
63 | |
64 // Reset state at the end of test. | |
65 chromeos::LoginState::Shutdown(); | |
66 } | |
67 | |
68 TEST_F(ExtensionTabUtilDelegateChromeOSTest, | |
69 FilterInsidePublicSessionNonWhitelisted) { | |
70 // Set Public Session state. | |
71 chromeos::LoginState::Initialize(); | |
Devlin
2017/05/03 15:14:15
This pattern:
chromeos::LoginState::Initialize();
Ivan Šandrk
2017/05/03 17:52:46
Yes, perfect! Done.
Logged a bug for myself to re
| |
72 chromeos::LoginState::Get()->SetLoggedInState( | |
Devlin
2017/05/03 15:14:15
ditto re indentation
| |
73 chromeos::LoginState::LOGGED_IN_ACTIVE, | |
74 chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT); | |
75 | |
76 delegate_.ScrubTabForExtension(kNonWhitelistedId, &tab_); | |
48 EXPECT_EQ(kFilteredUrl, *tab_.url); | 77 EXPECT_EQ(kFilteredUrl, *tab_.url); |
49 | 78 |
50 // Reset state at the end of test. | 79 // Reset state at the end of test. |
51 chromeos::LoginState::Shutdown(); | 80 chromeos::LoginState::Shutdown(); |
52 } | 81 } |
53 | 82 |
54 } // namespace extensions | 83 } // namespace extensions |
OLD | NEW |