Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / log_private / log_private_apitest_chromeos.cc
blobdac69c7dc9740bbb2039ab3d85274bf7bd27f79f
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
3 // found in the LICENSE file.
5 #include <string>
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chromeos/dbus/dbus_thread_manager.h"
12 #include "chromeos/dbus/fake_debug_daemon_client.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "extensions/common/extension_builder.h"
15 #include "net/dns/mock_host_resolver.h"
16 #include "net/test/embedded_test_server/embedded_test_server.h"
17 #include "net/test/embedded_test_server/http_request.h"
18 #include "net/test/embedded_test_server/http_response.h"
20 using net::test_server::BasicHttpResponse;
21 using net::test_server::HttpResponse;
22 using net::test_server::HttpRequest;
24 namespace {
26 class TestDebugDaemonClient : public chromeos::FakeDebugDaemonClient {
27 public:
28 explicit TestDebugDaemonClient(const base::FilePath& test_file)
29 : test_file_(test_file) {}
31 ~TestDebugDaemonClient() override {}
33 void DumpDebugLogs(bool is_compressed,
34 base::File file,
35 scoped_refptr<base::TaskRunner> task_runner,
36 const GetDebugLogsCallback& callback) override {
37 base::File* file_param = new base::File(file.Pass());
38 task_runner->PostTaskAndReply(
39 FROM_HERE,
40 base::Bind(
41 &GenerateTestLogDumpFile, test_file_, base::Owned(file_param)),
42 base::Bind(callback, true));
45 static void GenerateTestLogDumpFile(const base::FilePath& test_tar_file,
46 base::File* file) {
47 std::string test_file_content;
48 EXPECT_TRUE(base::ReadFileToString(test_tar_file, &test_file_content))
49 << "Cannot read content of file " << test_tar_file.value();
50 const int data_size = static_cast<int>(test_file_content.size());
51 EXPECT_EQ(data_size, file->Write(0, test_file_content.data(), data_size));
52 EXPECT_TRUE(file->SetLength(data_size));
53 file->Close();
56 private:
57 base::FilePath test_file_;
60 } // namespace
62 namespace extensions {
64 class LogPrivateApiTest : public ExtensionApiTest {
65 public:
66 LogPrivateApiTest() {}
68 ~LogPrivateApiTest() override {}
70 void SetUpInProcessBrowserTestFixture() override {
71 base::FilePath tar_file_path =
72 test_data_dir_.Append("log_private/dump_logs/system_logs.tar");
73 chromeos::DBusThreadManager::GetSetterForTesting()->SetDebugDaemonClient(
74 scoped_ptr<chromeos::DebugDaemonClient>(
75 new TestDebugDaemonClient(tar_file_path)));
76 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
79 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
80 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse);
81 response->set_code(net::HTTP_OK);
82 response->set_content(
83 "<html><head><title>LogPrivateTest</title>"
84 "</head><body>Hello!</body></html>");
85 return response.Pass();
89 IN_PROC_BROWSER_TEST_F(LogPrivateApiTest, DumpLogsAndCaptureEvents) {
90 // Setup dummy HTTP server.
91 host_resolver()->AddRule("www.test.com", "127.0.0.1");
92 ASSERT_TRUE(StartEmbeddedTestServer());
93 embedded_test_server()->RegisterRequestHandler(
94 base::Bind(&LogPrivateApiTest::HandleRequest, base::Unretained(this)));
96 ASSERT_TRUE(RunExtensionTest("log_private/dump_logs"));
99 } // namespace extensions