OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
7 #include "chrome/browser/extensions/extension_function_test_utils.h" | 7 #include "chrome/browser/extensions/extension_function_test_utils.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 #include "content/public/test/test_browser_context.h" | |
9 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
10 #include "extensions/browser/api/api_resource.h" | 11 #include "extensions/browser/api/api_resource.h" |
11 #include "extensions/browser/api/api_resource_manager.h" | 12 #include "extensions/browser/api/api_resource_manager.h" |
12 #include "extensions/common/extension.h" | 13 #include "extensions/common/extension.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
15 | 16 |
16 namespace utils = extension_function_test_utils; | 17 namespace utils = extension_function_test_utils; |
17 | 18 |
18 using content::BrowserThread; | 19 using content::BrowserThread; |
19 | 20 |
20 namespace extensions { | 21 namespace extensions { |
21 | 22 |
22 class ApiResourceManagerUnitTest : public testing::Test { | 23 class ApiResourceManagerUnitTest : public testing::Test { |
23 private: | 24 private: |
24 content::TestBrowserThreadBundle thread_bundle_; | 25 content::TestBrowserThreadBundle thread_bundle_; |
25 }; | 26 }; |
26 | 27 |
27 class FakeApiResource : public ApiResource { | 28 class FakeApiResource : public ApiResource { |
28 public: | 29 public: |
29 explicit FakeApiResource(const std::string& owner_extension_id) | 30 explicit FakeApiResource(const std::string& owner_extension_id) |
30 : ApiResource(owner_extension_id) {} | 31 : ApiResource(owner_extension_id) {} |
31 virtual ~FakeApiResource() {} | 32 virtual ~FakeApiResource() {} |
32 static const BrowserThread::ID kThreadId = BrowserThread::UI; | 33 static const BrowserThread::ID kThreadId = BrowserThread::UI; |
33 }; | 34 }; |
34 | 35 |
35 TEST_F(ApiResourceManagerUnitTest, TwoAppsCannotShareResources) { | 36 TEST_F(ApiResourceManagerUnitTest, TwoAppsCannotShareResources) { |
37 scoped_ptr<content::TestBrowserContext> browser_context( | |
38 new content::TestBrowserContext()); | |
36 scoped_ptr<ApiResourceManager<FakeApiResource> > manager( | 39 scoped_ptr<ApiResourceManager<FakeApiResource> > manager( |
37 new ApiResourceManager<FakeApiResource>(NULL)); | 40 new ApiResourceManager<FakeApiResource>(browser_context.get())); |
Devlin
2014/06/25 19:59:54
If I had to guess, I think the reason that the tes
| |
38 scoped_refptr<extensions::Extension> extension_one( | 41 scoped_refptr<extensions::Extension> extension_one( |
39 utils::CreateEmptyExtension("one")); | 42 utils::CreateEmptyExtension("one")); |
40 scoped_refptr<extensions::Extension> extension_two( | 43 scoped_refptr<extensions::Extension> extension_two( |
41 utils::CreateEmptyExtension("two")); | 44 utils::CreateEmptyExtension("two")); |
42 | 45 |
43 const std::string extension_one_id(extension_one->id()); | 46 const std::string extension_one_id(extension_one->id()); |
44 const std::string extension_two_id(extension_two->id()); | 47 const std::string extension_two_id(extension_two->id()); |
45 | 48 |
46 int resource_one_id = manager->Add(new FakeApiResource(extension_one_id)); | 49 int resource_one_id = manager->Add(new FakeApiResource(extension_one_id)); |
47 int resource_two_id = manager->Add(new FakeApiResource(extension_two_id)); | 50 int resource_two_id = manager->Add(new FakeApiResource(extension_two_id)); |
48 CHECK(resource_one_id); | 51 CHECK(resource_one_id); |
49 CHECK(resource_two_id); | 52 CHECK(resource_two_id); |
50 | 53 |
51 // Confirm each extension can get its own resource. | 54 // Confirm each extension can get its own resource. |
52 ASSERT_TRUE(manager->Get(extension_one_id, resource_one_id) != NULL); | 55 ASSERT_TRUE(manager->Get(extension_one_id, resource_one_id) != NULL); |
53 ASSERT_TRUE(manager->Get(extension_two_id, resource_two_id) != NULL); | 56 ASSERT_TRUE(manager->Get(extension_two_id, resource_two_id) != NULL); |
54 | 57 |
55 // Confirm neither extension can get the other's resource. | 58 // Confirm neither extension can get the other's resource. |
56 ASSERT_TRUE(manager->Get(extension_one_id, resource_two_id) == NULL); | 59 ASSERT_TRUE(manager->Get(extension_one_id, resource_two_id) == NULL); |
57 ASSERT_TRUE(manager->Get(extension_two_id, resource_one_id) == NULL); | 60 ASSERT_TRUE(manager->Get(extension_two_id, resource_one_id) == NULL); |
58 | 61 |
59 // And make sure we're not susceptible to any Jedi mind tricks. | 62 // And make sure we're not susceptible to any Jedi mind tricks. |
60 ASSERT_TRUE(manager->Get(std::string(), resource_one_id) == NULL); | 63 ASSERT_TRUE(manager->Get(std::string(), resource_one_id) == NULL); |
61 } | 64 } |
62 | 65 |
63 } // namespace extensions | 66 } // namespace extensions |
OLD | NEW |