blob: ff182eb44ef5539bc5e1314675b298423e7d52b9 [file] [log] [blame]
asanka655d1112015-03-07 05:33:411// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/platform_util.h"
6
dcheng4af48582016-04-19 00:29:357#include <memory>
8
asanka655d1112015-03-07 05:33:419#include "base/bind.h"
10#include "base/callback.h"
11#include "base/files/file_util.h"
12#include "base/files/scoped_temp_dir.h"
asanka655d1112015-03-07 05:33:4113#include "base/run_loop.h"
Avi Drissman5f0fb8c2018-12-25 23:20:4914#include "base/stl_util.h"
avib896c712015-12-26 02:10:4315#include "build/build_config.h"
asanka655d1112015-03-07 05:33:4116#include "chrome/browser/platform_util_internal.h"
17#include "testing/gtest/include/gtest/gtest.h"
18
19#if defined(OS_CHROMEOS)
20#include "base/json/json_string_value_serializer.h"
21#include "base/values.h"
22#include "chrome/browser/chrome_content_browser_client.h"
23#include "chrome/browser/chromeos/file_manager/app_id.h"
24#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
hashimotoa53e7e82016-10-26 06:30:4725#include "chrome/browser/chromeos/fileapi/file_system_backend_delegate.h"
asanka655d1112015-03-07 05:33:4126#include "chrome/browser/extensions/extension_special_storage_policy.h"
27#include "chrome/test/base/browser_with_test_window_test.h"
28#include "content/public/browser/browser_context.h"
29#include "content/public/common/content_client.h"
asanka655d1112015-03-07 05:33:4130#include "extensions/browser/extension_registry.h"
31#include "extensions/common/extension.h"
32#include "storage/browser/fileapi/external_mount_points.h"
pwnall343665e72017-04-13 04:04:4033#include "storage/browser/test/mock_special_storage_policy.h"
asanka655d1112015-03-07 05:33:4134#include "storage/common/fileapi/file_system_types.h"
35#else
Gabriel Charettec7108742019-08-23 03:31:4036#include "content/public/test/browser_task_environment.h"
asanka655d1112015-03-07 05:33:4137#endif
38
39namespace platform_util {
40
41namespace {
42
43#if defined(OS_CHROMEOS)
44
45// ChromeContentBrowserClient subclass that sets up a custom file system backend
46// that allows the test to grant file access to the file manager extension ID
47// without having to install the extension.
tfarina2176f4b2015-09-17 07:09:2648class PlatformUtilTestContentBrowserClient : public ChromeContentBrowserClient {
asanka655d1112015-03-07 05:33:4149 public:
50 void GetAdditionalFileSystemBackends(
51 content::BrowserContext* browser_context,
52 const base::FilePath& storage_partition_path,
avid6d88b912017-01-13 00:16:0053 std::vector<std::unique_ptr<storage::FileSystemBackend>>*
54 additional_backends) override {
asanka655d1112015-03-07 05:33:4155 storage::ExternalMountPoints* external_mount_points =
56 content::BrowserContext::GetMountPoints(browser_context);
asanka655d1112015-03-07 05:33:4157
58 // New FileSystemBackend that uses our MockSpecialStoragePolicy.
avid6d88b912017-01-13 00:16:0059 additional_backends->push_back(
Jeremy Romanec48d7a2018-03-01 17:35:0960 std::make_unique<chromeos::FileSystemBackend>(
Austin Tankiang396756c2019-09-18 03:36:3961 nullptr, nullptr, nullptr, nullptr, nullptr, external_mount_points,
avid6d88b912017-01-13 00:16:0062 storage::ExternalMountPoints::GetSystemInstance()));
asanka655d1112015-03-07 05:33:41