Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // MediaFileSystemRegistry unit tests. | 5 // MediaFileSystemRegistry unit tests. |
| 6 | 6 |
| 7 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 7 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <set> | 13 #include <set> |
| 14 | 14 |
| 15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
| 18 #include "base/files/scoped_temp_dir.h" | 18 #include "base/files/scoped_temp_dir.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/memory/ptr_util.h" | |
| 20 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
| 21 #include "base/memory/scoped_vector.h" | 22 #include "base/memory/scoped_vector.h" |
| 22 #include "base/path_service.h" | 23 #include "base/path_service.h" |
| 23 #include "base/run_loop.h" | 24 #include "base/run_loop.h" |
| 24 #include "base/stl_util.h" | |
| 25 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/threading/sequenced_worker_pool.h" | 27 #include "base/threading/sequenced_worker_pool.h" |
| 28 #include "base/values.h" | 28 #include "base/values.h" |
| 29 #include "build/build_config.h" | 29 #include "build/build_config.h" |
| 30 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
| 31 #include "chrome/browser/extensions/test_extension_system.h" | 31 #include "chrome/browser/extensions/test_extension_system.h" |
| 32 #include "chrome/browser/media_galleries/media_file_system_context.h" | 32 #include "chrome/browser/media_galleries/media_file_system_context.h" |
| 33 #include "chrome/browser/media_galleries/media_galleries_preferences_factory.h" | 33 #include "chrome/browser/media_galleries/media_galleries_preferences_factory.h" |
| 34 #include "chrome/browser/media_galleries/media_galleries_test_util.h" | 34 #include "chrome/browser/media_galleries/media_galleries_test_util.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 } | 191 } |
| 192 | 192 |
| 193 class MockProfileSharedRenderProcessHostFactory | 193 class MockProfileSharedRenderProcessHostFactory |
| 194 : public content::RenderProcessHostFactory { | 194 : public content::RenderProcessHostFactory { |
| 195 public: | 195 public: |
| 196 MockProfileSharedRenderProcessHostFactory() {} | 196 MockProfileSharedRenderProcessHostFactory() {} |
| 197 ~MockProfileSharedRenderProcessHostFactory() override; | 197 ~MockProfileSharedRenderProcessHostFactory() override; |
| 198 | 198 |
| 199 // RPH created with this factory are owned by it. If the RPH is destroyed | 199 // RPH created with this factory are owned by it. If the RPH is destroyed |
| 200 // for testing purposes, it must be removed from the factory first. | 200 // for testing purposes, it must be removed from the factory first. |
| 201 content::MockRenderProcessHost* ReleaseRPH( | 201 std::unique_ptr<content::MockRenderProcessHost> ReleaseRPH( |
| 202 content::BrowserContext* browser_context); | 202 content::BrowserContext* browser_context); |
| 203 | 203 |
| 204 content::RenderProcessHost* CreateRenderProcessHost( | 204 content::RenderProcessHost* CreateRenderProcessHost( |
| 205 content::BrowserContext* browser_context, | 205 content::BrowserContext* browser_context, |
| 206 content::SiteInstance* site_instance) const override; | 206 content::SiteInstance* site_instance) const override; |
| 207 | 207 |
| 208 private: | 208 private: |
| 209 typedef std::map<content::BrowserContext*, content::MockRenderProcessHost*> | 209 mutable std::map<content::BrowserContext*, |
| 210 ProfileRPHMap; | 210 std::unique_ptr<content::MockRenderProcessHost>> |
| 211 mutable ProfileRPHMap rph_map_; | 211 rph_map_; |
| 212 | 212 |
| 213 DISALLOW_COPY_AND_ASSIGN(MockProfileSharedRenderProcessHostFactory); | 213 DISALLOW_COPY_AND_ASSIGN(MockProfileSharedRenderProcessHostFactory); |
| 214 }; | 214 }; |
| 215 | 215 |
| 216 class ProfileState { | 216 class ProfileState { |
| 217 public: | 217 public: |
| 218 explicit ProfileState( | 218 explicit ProfileState( |
| 219 MockProfileSharedRenderProcessHostFactory* rph_factory); | 219 MockProfileSharedRenderProcessHostFactory* rph_factory); |
| 220 ~ProfileState(); | 220 ~ProfileState(); |
| 221 | 221 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 CHECK_NE(a.name, b.name); // Name must be unique. | 390 CHECK_NE(a.name, b.name); // Name must be unique. |
| 391 return a.name < b.name; | 391 return a.name < b.name; |
| 392 } | 392 } |
| 393 | 393 |
| 394 /////////////////////////////////////////////// | 394 /////////////////////////////////////////////// |
| 395 // MockProfileSharedRenderProcessHostFactory // | 395 // MockProfileSharedRenderProcessHostFactory // |
| 396 /////////////////////////////////////////////// | 396 /////////////////////////////////////////////// |
| 397 | 397 |
| 398 MockProfileSharedRenderProcessHostFactory:: | 398 MockProfileSharedRenderProcessHostFactory:: |
| 399 ~MockProfileSharedRenderProcessHostFactory() { | 399 ~MockProfileSharedRenderProcessHostFactory() { |
| 400 base::STLDeleteValues(&rph_map_); | |
| 401 } | 400 } |
| 402 | 401 |
| 403 content::MockRenderProcessHost* | 402 std::unique_ptr<content::MockRenderProcessHost> |
| 404 MockProfileSharedRenderProcessHostFactory::ReleaseRPH( | 403 MockProfileSharedRenderProcessHostFactory::ReleaseRPH( |
| 405 content::BrowserContext* browser_context) { | 404 content::BrowserContext* browser_context) { |
| 406 ProfileRPHMap::iterator existing = rph_map_.find(browser_context); | 405 auto existing = rph_map_.find(browser_context); |
| 407 if (existing == rph_map_.end()) | 406 if (existing == rph_map_.end()) |
| 408 return NULL; | 407 return NULL; |
| 409 content::MockRenderProcessHost* result = existing->second; | 408 std::unique_ptr<content::MockRenderProcessHost> result = |
| 409 std::move(existing->second); | |
| 410 rph_map_.erase(existing); | 410 rph_map_.erase(existing); |
| 411 return result; | 411 return result; |
| 412 } | 412 } |
| 413 | 413 |
| 414 content::RenderProcessHost* | 414 content::RenderProcessHost* |
| 415 MockProfileSharedRenderProcessHostFactory::CreateRenderProcessHost( | 415 MockProfileSharedRenderProcessHostFactory::CreateRenderProcessHost( |
| 416 content::BrowserContext* browser_context, | 416 content::BrowserContext* browser_context, |
| 417 content::SiteInstance* site_instance) const { | 417 content::SiteInstance* site_instance) const { |
| 418 ProfileRPHMap::const_iterator existing = rph_map_.find(browser_context); | 418 auto existing = rph_map_.find(browser_context); |
| 419 if (existing != rph_map_.end()) | 419 if (existing != rph_map_.end()) |
| 420 return existing->second; | 420 return existing->second.get(); |
| 421 rph_map_[browser_context] = | 421 rph_map_[browser_context] = |
| 422 new content::MockRenderProcessHost(browser_context); | 422 base::MakeUnique<content::MockRenderProcessHost>(browser_context); |
| 423 return rph_map_[browser_context]; | 423 return rph_map_[browser_context].get(); |
| 424 } | 424 } |
| 425 | 425 |
| 426 ////////////////// | 426 ////////////////// |
| 427 // ProfileState // | 427 // ProfileState // |
| 428 ////////////////// | 428 ////////////////// |
| 429 | 429 |
| 430 ProfileState::ProfileState( | 430 ProfileState::ProfileState( |
| 431 MockProfileSharedRenderProcessHostFactory* rph_factory) | 431 MockProfileSharedRenderProcessHostFactory* rph_factory) |
| 432 : num_comparisons_(0), | 432 : num_comparisons_(0), |
| 433 profile_(new TestingProfile()) { | 433 profile_(new TestingProfile()) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 445 | 445 |
| 446 all_permission_extension_ = | 446 all_permission_extension_ = |
| 447 AddMediaGalleriesApp("all", all_permissions, profile_.get()); | 447 AddMediaGalleriesApp("all", all_permissions, profile_.get()); |
| 448 regular_permission_extension_ = | 448 regular_permission_extension_ = |
| 449 AddMediaGalleriesApp("regular", read_permissions, profile_.get()); | 449 AddMediaGalleriesApp("regular", read_permissions, profile_.get()); |
| 450 no_permissions_extension_ = | 450 no_permissions_extension_ = |
| 451 AddMediaGalleriesApp("no", read_permissions, profile_.get()); | 451 AddMediaGalleriesApp("no", read_permissions, profile_.get()); |
| 452 | 452 |
| 453 single_web_contents_.reset( | 453 single_web_contents_.reset( |
| 454 content::WebContentsTester::CreateTestWebContents(profile_.get(), NULL)); | 454 content::WebContentsTester::CreateTestWebContents(profile_.get(), NULL)); |
| 455 single_rph_ = rph_factory->ReleaseRPH(profile_.get()); | 455 single_rph_ = rph_factory->ReleaseRPH(profile_.get()).release(); |
|
Nico
2016/10/24 18:41:02
as far as i can tell nothing ever reads this varia
Lei Zhang
2016/10/24 18:45:14
The |single_rph_| declaration above has this comme
Nico
2016/10/24 18:49:00
But why is this in an env var then? And if somethi
Avi (use Gerrit)
2016/10/24 19:15:37
Let me remove this set of files from this CL and f
| |
| 456 | 456 |
| 457 shared_web_contents1_.reset( | 457 shared_web_contents1_.reset( |
| 458 content::WebContentsTester::CreateTestWebContents(profile_.get(), NULL)); | 458 content::WebContentsTester::CreateTestWebContents(profile_.get(), NULL)); |
| 459 shared_web_contents2_.reset( | 459 shared_web_contents2_.reset( |
| 460 content::WebContentsTester::CreateTestWebContents(profile_.get(), NULL)); | 460 content::WebContentsTester::CreateTestWebContents(profile_.get(), NULL)); |
| 461 shared_rph_ = rph_factory->ReleaseRPH(profile_.get()); | 461 shared_rph_ = rph_factory->ReleaseRPH(profile_.get()).release(); |
| 462 } | 462 } |
| 463 | 463 |
| 464 ProfileState::~ProfileState() { | 464 ProfileState::~ProfileState() { |
| 465 // TestExtensionSystem uses DeleteSoon, so we need to delete the profiles | 465 // TestExtensionSystem uses DeleteSoon, so we need to delete the profiles |
| 466 // and then run the message queue to clean up. But first we have to | 466 // and then run the message queue to clean up. But first we have to |
| 467 // delete everything that references the profile. | 467 // delete everything that references the profile. |
| 468 single_web_contents_.reset(); | 468 single_web_contents_.reset(); |
| 469 shared_web_contents1_.reset(); | 469 shared_web_contents1_.reset(); |
| 470 shared_web_contents2_.reset(); | 470 shared_web_contents2_.reset(); |
| 471 profile_.reset(); | 471 profile_.reset(); |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1071 fs_info.begin()->second.fsid).empty()); | 1071 fs_info.begin()->second.fsid).empty()); |
| 1072 | 1072 |
| 1073 // Revoke permission and ensure that the file system is revoked. | 1073 // Revoke permission and ensure that the file system is revoked. |
| 1074 SetGalleryPermission(profile_state, | 1074 SetGalleryPermission(profile_state, |
| 1075 profile_state->regular_permission_extension(), | 1075 profile_state->regular_permission_extension(), |
| 1076 device_id, | 1076 device_id, |
| 1077 false /*has access*/); | 1077 false /*has access*/); |
| 1078 EXPECT_TRUE(test_file_system_context()->GetRegisteredPath( | 1078 EXPECT_TRUE(test_file_system_context()->GetRegisteredPath( |
| 1079 fs_info.begin()->second.fsid).empty()); | 1079 fs_info.begin()->second.fsid).empty()); |
| 1080 } | 1080 } |
| OLD | NEW |