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/page_capture/page_capture_apitest.cc

Issue 2552203007: Public Sessions - prompt the user for pageCapture requests (Closed)
Patch Set: Nitfix Created 3 years, 10 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/base_switches.h" 5 #include "base/base_switches.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "chrome/browser/extensions/api/page_capture/page_capture_api.h" 7 #include "chrome/browser/extensions/api/page_capture/page_capture_api.h"
8 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chromeos/login/login_state.h"
10 #include "content/public/common/content_switches.h" 11 #include "content/public/common/content_switches.h"
11 #include "content/public/test/test_utils.h" 12 #include "content/public/test/test_utils.h"
13 #include "extensions/browser/extension_dialog_auto_confirm.h"
12 #include "net/dns/mock_host_resolver.h" 14 #include "net/dns/mock_host_resolver.h"
13 15
14 using extensions::PageCaptureSaveAsMHTMLFunction; 16 using extensions::PageCaptureSaveAsMHTMLFunction;
17 using extensions::ScopedTestDialogAutoConfirm;
15 18
16 class ExtensionPageCaptureApiTest : public ExtensionApiTest { 19 class ExtensionPageCaptureApiTest : public ExtensionApiTest {
17 public: 20 public:
18 void SetUpCommandLine(base::CommandLine* command_line) override { 21 void SetUpCommandLine(base::CommandLine* command_line) override {
19 ExtensionApiTest::SetUpCommandLine(command_line); 22 ExtensionApiTest::SetUpCommandLine(command_line);
20 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); 23 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc");
21 } 24 }
22 }; 25 };
23 26
24 class PageCaptureSaveAsMHTMLDelegate 27 class PageCaptureSaveAsMHTMLDelegate
(...skipping 12 matching lines...) Expand all
37 } 40 }
38 41
39 base::FilePath temp_file_; 42 base::FilePath temp_file_;
40 }; 43 };
41 44
42 IN_PROC_BROWSER_TEST_F(ExtensionPageCaptureApiTest, SaveAsMHTML) { 45 IN_PROC_BROWSER_TEST_F(ExtensionPageCaptureApiTest, SaveAsMHTML) {
43 host_resolver()->AddRule("www.a.com", "127.0.0.1"); 46 host_resolver()->AddRule("www.a.com", "127.0.0.1");
44 ASSERT_TRUE(StartEmbeddedTestServer()); 47 ASSERT_TRUE(StartEmbeddedTestServer());
45 PageCaptureSaveAsMHTMLDelegate delegate; 48 PageCaptureSaveAsMHTMLDelegate delegate;
46 ASSERT_TRUE(RunExtensionTest("page_capture")) << message_; 49 ASSERT_TRUE(RunExtensionTest("page_capture")) << message_;
50 // Make sure the MHTML data gets written to the temporary file.
47 ASSERT_FALSE(delegate.temp_file_.empty()); 51 ASSERT_FALSE(delegate.temp_file_.empty());
48 // Flush the message loops to make sure the delete happens. 52 // Flush the message loops to make sure the delete happens.
49 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); 53 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
50 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); 54 content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
55 // Make sure the temporary file is destroyed once the javascript side reads
56 // the contents.
51 ASSERT_FALSE(base::PathExists(delegate.temp_file_)); 57 ASSERT_FALSE(base::PathExists(delegate.temp_file_));
52 } 58 }
59
60 #if defined(OS_CHROMEOS)
61 IN_PROC_BROWSER_TEST_F(ExtensionPageCaptureApiTest,
62 PublicSessionRequestAllowed) {
63 host_resolver()->AddRule("www.a.com", "127.0.0.1");
64 ASSERT_TRUE(StartEmbeddedTestServer());
65 PageCaptureSaveAsMHTMLDelegate delegate;
66 // Set Public Session state.
67 chromeos::LoginState::Get()->SetLoggedInState(
68 chromeos::LoginState::LOGGED_IN_ACTIVE,
69 chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT);
70 // Resolve Permission dialog with Allow.
71 ScopedTestDialogAutoConfirm auto_confirm(ScopedTestDialogAutoConfirm::ACCEPT);
72 ASSERT_TRUE(RunExtensionTest("page_capture")) << message_;
73 ASSERT_FALSE(delegate.temp_file_.empty());
74 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
75 content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
76 ASSERT_FALSE(base::PathExists(delegate.temp_file_));
77 }
78
79 IN_PROC_BROWSER_TEST_F(ExtensionPageCaptureApiTest,
80 PublicSessionRequestDenied) {
81 host_resolver()->AddRule("www.a.com", "127.0.0.1");
82 ASSERT_TRUE(StartEmbeddedTestServer());
83 // Set Public Session state.
84 chromeos::LoginState::Get()->SetLoggedInState(
85 chromeos::LoginState::LOGGED_IN_ACTIVE,
86 chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT);
87 // Resolve Permission dialog with Deny.
88 ScopedTestDialogAutoConfirm auto_confirm(ScopedTestDialogAutoConfirm::CANCEL);
89 ASSERT_TRUE(RunExtensionTestWithArg("page_capture", "REQUEST_DENIED"))
90 << message_;
91 }
92 #endif // defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698