Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: chrome/browser/extensions/api/log_private/log_private_apitest_chromeos.cc

Issue 329853010: Additional methods for chrome.logPrivate API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 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 <string>
6
7 #include "base/file_util.h"
8 #include "base/files/file_path.h"
9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chromeos/dbus/fake_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"
19
20 using net::test_server::BasicHttpResponse;
21 using net::test_server::HttpResponse;
22 using net::test_server::HttpRequest;
23
24 namespace {
25
26 class TestDebugDaemonClient : public chromeos::FakeDebugDaemonClient {
27 public:
28 explicit TestDebugDaemonClient(const base::FilePath& test_file)
29 : test_file_(test_file) {}
30
31 virtual ~TestDebugDaemonClient() {}
32
33 virtual void DumpDebugLogs(bool is_compressed,
34 base::File file,
35 const GetDebugLogsCallback& callback) OVERRIDE {
36 base::File* file_param = new base::File(file.Pass());
37 content::BrowserThread::PostBlockingPoolTaskAndReply(
38 FROM_HERE,
39 base::Bind(
40 &GenerateTestLogDumpFile, test_file_, base::Owned(file_param)),
41 base::Bind(callback, true));
42 }
43
44 static void GenerateTestLogDumpFile(const base::FilePath& test_tar_file,
45 base::File* file) {
46 std::string test_file_content;
47 EXPECT_TRUE(base::ReadFileToString(test_tar_file, &test_file_content))
48 << "Cannot read content of file " << test_tar_file.value();
49 const int data_size = static_cast<int>(test_file_content.size());
50 EXPECT_EQ(data_size, file->Write(0, test_file_content.data(), data_size));
51 EXPECT_TRUE(file->SetLength(data_size));
52 file->Close();
53 }
54
55 private:
56 base::FilePath test_file_;
57 };
58
59 } // namespace
60
61 namespace extensions {
62
63 class LogPrivateApiTest : public ExtensionApiTest {
64 public:
65 LogPrivateApiTest() {}
66
67 virtual ~LogPrivateApiTest() {}
68
69 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
70 chromeos::FakeDBusThreadManager* fake_dbus_thread_manager =
71 new chromeos::FakeDBusThreadManager;
72 fake_dbus_thread_manager->SetFakeClients();
73 base::FilePath tar_file_path =
74 test_data_dir_.Append("log_private/dump_logs/system_logs.tar");
75 fake_dbus_thread_manager->SetDebugDaemonClient(
76 scoped_ptr<chromeos::DebugDaemonClient>(
77 new TestDebugDaemonClient(tar_file_path)));
78 chromeos::DBusThreadManager::SetInstanceForTesting(
79 fake_dbus_thread_manager);
80 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
81 }
82
83 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
84 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse);
85 response->set_code(net::HTTP_OK);
86 response->set_content(
87 "<html><head><title>LogPrivateTest</title>"
88 "</head><body>Hello!</body></html>");
89 return response.PassAs<HttpResponse>();
90 }
91 };
92
93 IN_PROC_BROWSER_TEST_F(LogPrivateApiTest, DumpLogsAndCaptureEvents) {
94 // Setup dummy HTTP server.
95 host_resolver()->AddRule("www.test.com", "127.0.0.1");
96 ASSERT_TRUE(StartEmbeddedTestServer());
97 embedded_test_server()->RegisterRequestHandler(
98 base::Bind(&LogPrivateApiTest::HandleRequest, base::Unretained(this)));
99
100 ASSERT_TRUE(RunExtensionTest("log_private/dump_logs"));
101 }
102
103 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698