| 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 "content/public/browser/browser_thread.h" | 7 #include "content/public/browser/browser_thread.h" |
| 8 #include "extensions/browser/api/api_resource.h" | 8 #include "extensions/browser/api/api_resource.h" |
| 9 #include "extensions/browser/api/api_resource_manager.h" | 9 #include "extensions/browser/api/api_resource_manager.h" |
| 10 #include "extensions/browser/api_unittest.h" | 10 #include "extensions/browser/api_unittest.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 class FakeApiResource : public ApiResource { | 22 class FakeApiResource : public ApiResource { |
| 23 public: | 23 public: |
| 24 explicit FakeApiResource(const std::string& owner_extension_id) | 24 explicit FakeApiResource(const std::string& owner_extension_id) |
| 25 : ApiResource(owner_extension_id) {} | 25 : ApiResource(owner_extension_id) {} |
| 26 ~FakeApiResource() override {} | 26 ~FakeApiResource() override {} |
| 27 static const BrowserThread::ID kThreadId = BrowserThread::UI; | 27 static const BrowserThread::ID kThreadId = BrowserThread::UI; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 TEST_F(ApiResourceManagerUnitTest, TwoAppsCannotShareResources) { | 30 TEST_F(ApiResourceManagerUnitTest, TwoAppsCannotShareResources) { |
| 31 scoped_ptr<ApiResourceManager<FakeApiResource>> manager( | 31 std::unique_ptr<ApiResourceManager<FakeApiResource>> manager( |
| 32 new ApiResourceManager<FakeApiResource>(browser_context())); | 32 new ApiResourceManager<FakeApiResource>(browser_context())); |
| 33 scoped_refptr<extensions::Extension> extension_one = | 33 scoped_refptr<extensions::Extension> extension_one = |
| 34 test_util::CreateEmptyExtension("one"); | 34 test_util::CreateEmptyExtension("one"); |
| 35 scoped_refptr<extensions::Extension> extension_two = | 35 scoped_refptr<extensions::Extension> extension_two = |
| 36 test_util::CreateEmptyExtension("two"); | 36 test_util::CreateEmptyExtension("two"); |
| 37 | 37 |
| 38 const std::string extension_one_id(extension_one->id()); | 38 const std::string extension_one_id(extension_one->id()); |
| 39 const std::string extension_two_id(extension_two->id()); | 39 const std::string extension_two_id(extension_two->id()); |
| 40 | 40 |
| 41 int resource_one_id = manager->Add(new FakeApiResource(extension_one_id)); | 41 int resource_one_id = manager->Add(new FakeApiResource(extension_one_id)); |
| 42 int resource_two_id = manager->Add(new FakeApiResource(extension_two_id)); | 42 int resource_two_id = manager->Add(new FakeApiResource(extension_two_id)); |
| 43 CHECK(resource_one_id); | 43 CHECK(resource_one_id); |
| 44 CHECK(resource_two_id); | 44 CHECK(resource_two_id); |
| 45 | 45 |
| 46 // Confirm each extension can get its own resource. | 46 // Confirm each extension can get its own resource. |
| 47 ASSERT_TRUE(manager->Get(extension_one_id, resource_one_id) != NULL); | 47 ASSERT_TRUE(manager->Get(extension_one_id, resource_one_id) != NULL); |
| 48 ASSERT_TRUE(manager->Get(extension_two_id, resource_two_id) != NULL); | 48 ASSERT_TRUE(manager->Get(extension_two_id, resource_two_id) != NULL); |
| 49 | 49 |
| 50 // Confirm neither extension can get the other's resource. | 50 // Confirm neither extension can get the other's resource. |
| 51 ASSERT_TRUE(manager->Get(extension_one_id, resource_two_id) == NULL); | 51 ASSERT_TRUE(manager->Get(extension_one_id, resource_two_id) == NULL); |
| 52 ASSERT_TRUE(manager->Get(extension_two_id, resource_one_id) == NULL); | 52 ASSERT_TRUE(manager->Get(extension_two_id, resource_one_id) == NULL); |
| 53 | 53 |
| 54 // And make sure we're not susceptible to any Jedi mind tricks. | 54 // And make sure we're not susceptible to any Jedi mind tricks. |
| 55 ASSERT_TRUE(manager->Get(std::string(), resource_one_id) == NULL); | 55 ASSERT_TRUE(manager->Get(std::string(), resource_one_id) == NULL); |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace extensions | 58 } // namespace extensions |
| OLD | NEW |