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
3 // found in the LICENSE file.
5 #include "base/files/file_path.h"
6 #include "base/files/file_util.h"
7 #include "base/json/json_file_value_serializer.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h"
11 #include "base/version.h"
12 #include "build/build_config.h"
13 #include "chrome/browser/component_updater/flash_component_installer.h"
14 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/pepper_flash.h"
16 #include "content/public/test/test_browser_thread.h"
17 #include "ppapi/shared_impl/test_globals.h"
19 #include "testing/gtest/include/gtest/gtest.h"
21 using content::BrowserThread
;
23 namespace component_updater
{
26 // File name of the Pepper Flash plugin on different platforms.
27 const base::FilePath::CharType kDataPath
[] =
28 #if defined(OS_MACOSX)
29 #if defined(ARCH_CPU_X86)
30 FILE_PATH_LITERAL("components/flapper/mac");
31 #elif defined(ARCH_CPU_X86_64)
32 FILE_PATH_LITERAL("components/flapper/mac_x64");
34 FILE_PATH_LITERAL("components/flapper/NONEXISTENT");
37 #if defined(ARCH_CPU_X86)
38 FILE_PATH_LITERAL("components\\flapper\\windows");
39 #elif defined(ARCH_CPU_X86_64)
40 FILE_PATH_LITERAL("components\\flapper\\windows_x64");
42 FILE_PATH_LITERAL("components\\flapper\\NONEXISTENT");
44 #else // OS_LINUX, etc.
45 #if defined(ARCH_CPU_X86)
46 FILE_PATH_LITERAL("components/flapper/linux");
47 #elif defined(ARCH_CPU_X86_64)
48 FILE_PATH_LITERAL("components/flapper/linux_x64");
50 FILE_PATH_LITERAL("components/flapper/NONEXISTENT");
55 // TODO(viettrungluu): Separate out into two separate tests; use a test fixture.
56 TEST(ComponentInstallerTest
, PepperFlashCheck
) {
57 base::MessageLoop message_loop
;
58 content::TestBrowserThread
ui_thread(BrowserThread::UI
, &message_loop
);
60 ppapi::PpapiGlobals::PerThreadForTest per_thread_for_test
;
61 ppapi::TestGlobals
test_globals(per_thread_for_test
);
62 ppapi::PpapiGlobals::SetPpapiGlobalsOnThreadForTest(&test_globals
);
64 // The test directory is chrome/test/data/components/flapper.
65 base::FilePath manifest
;
66 PathService::Get(chrome::DIR_TEST_DATA
, &manifest
);
67 manifest
= manifest
.Append(kDataPath
);
68 manifest
= manifest
.AppendASCII("manifest.json");
70 if (!base::PathExists(manifest
)) {
71 LOG(WARNING
) << "No test manifest available. Skipping.";
75 JSONFileValueDeserializer
deserializer(manifest
);
77 scoped_ptr
<base::DictionaryValue
> root(static_cast<base::DictionaryValue
*>(
78 deserializer
.Deserialize(NULL
, &error
)));
80 ASSERT_TRUE(root
->IsType(base::Value::TYPE_DICTIONARY
));
82 // This checks that the whole manifest is compatible.
84 EXPECT_TRUE(chrome::CheckPepperFlashManifest(*root
, &version
));
85 EXPECT_TRUE(version
.IsValid());
88 } // namespace component_updater