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

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

Issue 2934163002: Delete the logPrivate APIs (Closed)
Patch Set: Roll back docs changes Created 3 years, 6 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 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.
4
5 #include <string>
6 #include <utility>
7
8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h"
10 #include "base/task_scheduler/post_task.h"
11 #include "chrome/browser/extensions/extension_apitest.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "chromeos/dbus/fake_debug_daemon_client.h"
15 #include "extensions/common/extension_builder.h"
16 #include "net/dns/mock_host_resolver.h"
17 #include "net/test/embedded_test_server/embedded_test_server.h"
18 #include "net/test/embedded_test_server/http_request.h"
19 #include "net/test/embedded_test_server/http_response.h"
20
21 using net::test_server::BasicHttpResponse;
22 using net::test_server::HttpResponse;
23 using net::test_server::HttpRequest;
24
25 namespace {
26
27 class TestDebugDaemonClient : public chromeos::FakeDebugDaemonClient {
28 public:
29 explicit TestDebugDaemonClient(const base::FilePath& test_file)
30 : test_file_(test_file) {}
31
32 ~TestDebugDaemonClient() override {}
33
34 void DumpDebugLogs(bool is_compressed,
35 int file_descriptor,
36 const GetDebugLogsCallback& callback) override {
37 // dup() is needed as the file descriptor will be closed on the client side.
38 base::File* file_param = new base::File(dup(file_descriptor));
39 base::PostTaskWithTraitsAndReply(
40 FROM_HERE, {base::MayBlock()},
41 base::Bind(&GenerateTestLogDumpFile, test_file_,
42 base::Owned(file_param)),
43 base::Bind(callback, true));
44 }
45
46 static void GenerateTestLogDumpFile(const base::FilePath& test_tar_file,
47 base::File* file) {
48 std::string test_file_content;
49 EXPECT_TRUE(base::ReadFileToString(test_tar_file, &test_file_content))
50 << "Cannot read content of file " << test_tar_file.value();
51 const int data_size = static_cast<int>(test_file_content.size());
52 EXPECT_EQ(data_size, file->Write(0, test_file_content.data(), data_size));
53 EXPECT_TRUE(file->SetLength(data_size));
54 file->Close();
55 }
56
57 private:
58 base::FilePath test_file_;
59 };
60
61 } // namespace
62
63 namespace extensions {
64
65 class LogPrivateApiTest : public ExtensionApiTest {
66 public:
67 LogPrivateApiTest() {}
68
69 ~LogPrivateApiTest() override {}
70
71 void SetUpInProcessBrowserTestFixture() override {
72 base::FilePath tar_file_path =
73 test_data_dir_.Append("log_private/dump_logs/system_logs.tar");
74 chromeos::DBusThreadManager::GetSetterForTesting()->SetDebugDaemonClient(
75 std::unique_ptr<chromeos::DebugDaemonClient>(
76 new TestDebugDaemonClient(tar_file_path)));
77 host_resolver()->AddRule("www.test.com", "127.0.0.1");
78 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
79 }
80
81 std::unique_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
82 std::unique_ptr<BasicHttpResponse> response(new BasicHttpResponse);
83 response->set_code(net::HTTP_OK);
84 response->set_content(
85 "<html><head><title>LogPrivateTest</title>"
86 "</head><body>Hello!</body></html>");
87 return std::move(response);
88 }
89 };
90
91 IN_PROC_BROWSER_TEST_F(LogPrivateApiTest, DumpLogsAndCaptureEvents) {
92 // Setup dummy HTTP server.
93 embedded_test_server()->RegisterRequestHandler(
94 base::Bind(&LogPrivateApiTest::HandleRequest, base::Unretained(this)));
95 ASSERT_TRUE(StartEmbeddedTestServer());
96
97 ASSERT_TRUE(RunExtensionTest("log_private/dump_logs"));
98 }
99
100 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698