Skip to content

Commit 09d5c2f

Browse files
committed
[test] local flash browser_test for nwjs#5706
1 parent 3243592 commit 09d5c2f

File tree

25 files changed

+189
-3
lines changed

25 files changed

+189
-3
lines changed

src/nwjs_browsertest.cc

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
#include "components/guest_view/browser/guest_view_manager_factory.h"
5555
#include "components/guest_view/browser/test_guest_view_manager.h"
5656
#include "content/public/browser/ax_event_notification_details.h"
57+
#include "content/public/browser/browser_child_process_host_iterator.h"
58+
#include "content/public/browser/child_process_data.h"
59+
#include "content/public/common/process_type.h"
5760
#include "content/public/browser/gpu_data_manager.h"
5861
#include "content/public/browser/interstitial_page.h"
5962
#include "content/public/browser/interstitial_page_delegate.h"
@@ -118,6 +121,7 @@ using task_manager::browsertest_util::MatchBackground;
118121
using task_manager::browsertest_util::MatchWebView;
119122
using task_manager::browsertest_util::WaitForTaskManagerRows;
120123
using ui::MenuModel;
124+
using content::BrowserThread;
121125

122126
namespace {
123127
const char kEmptyResponsePath[] = "/close-socket";
@@ -862,11 +866,63 @@ class NWJSWebViewTest : public NWWebViewTestBase, public testing::WithParamInter
862866

863867
INSTANTIATE_TEST_CASE_P(NWJSWebViewTests, NWJSWebViewTest, testing::Bool());
864868

869+
class NWAppTest : public extensions::PlatformAppBrowserTest {
870+
public:
871+
NWAppTest() {}
872+
~NWAppTest() override {}
873+
void SetUpCommandLine(base::CommandLine* command_line) override {
874+
extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
875+
PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir_);
876+
test_data_dir_ = test_data_dir_.Append(FILE_PATH_LITERAL("content"));
877+
test_data_dir_ = test_data_dir_.Append(FILE_PATH_LITERAL("nw"));
878+
test_data_dir_ = test_data_dir_.Append(FILE_PATH_LITERAL("test"));
879+
test_data_dir_ = test_data_dir_.Append(FILE_PATH_LITERAL("data"));
880+
}
881+
static void CountPluginProcesses(int* count, const base::Closure& quit_task) {
882+
for (content::BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) {
883+
if (iter.GetData().process_type == content::PROCESS_TYPE_PPAPI_PLUGIN)
884+
(*count)++;
885+
}
886+
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit_task);
887+
}
888+
static void EnsureFlashProcessCount(int expected) {
889+
int actual = 0;
890+
scoped_refptr<content::MessageLoopRunner> runner =
891+
new content::MessageLoopRunner;
892+
BrowserThread::PostTask(
893+
BrowserThread::IO,
894+
FROM_HERE,
895+
base::Bind(&CountPluginProcesses, &actual, runner->QuitClosure()));
896+
runner->Run();
897+
ASSERT_EQ(expected, actual);
898+
}
899+
900+
};
865901

866902
void NWTimeoutCallback(const std::string& timeout_message) {
867903
base::MessageLoop::current()->QuitWhenIdle();
868904
}
869905

906+
IN_PROC_BROWSER_TEST_F(NWAppTest, LocalFlash) {
907+
std::string contents;
908+
base::FilePath test_dir = test_data_dir_.Append(FILE_PATH_LITERAL("platform_apps")).Append(FILE_PATH_LITERAL("local_flash"));
909+
base::FilePath tpl_path = test_dir.Append(FILE_PATH_LITERAL("index.tpl"));
910+
base::FilePath swf_path = test_dir.Append(FILE_PATH_LITERAL("test.swf"));
911+
base::FilePath index_html = test_dir.Append(FILE_PATH_LITERAL("index.html"));
912+
ASSERT_TRUE(base::ReadFileToString(tpl_path, &contents));
913+
GURL swf_url = net::FilePathToFileURL(swf_path);
914+
base::ReplaceSubstringsAfterOffset(&contents, 0, "<swf_path>", swf_url.spec());
915+
EXPECT_GT(base::WriteFile(index_html, contents.c_str(), contents.size()), 0);
916+
917+
LoadAndLaunchPlatformApp("local_flash", "Launched");
918+
content::WebContents* web_contents = GetFirstAppWindowWebContents();
919+
ASSERT_TRUE(web_contents);
920+
base::string16 expected_title(base::ASCIIToUTF16("Loaded"));
921+
content::TitleWatcher title_watcher(web_contents, expected_title);
922+
923+
EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
924+
}
925+
870926
IN_PROC_BROWSER_TEST_P(NWJSWebViewTest, LocalPDF) {
871927
std::string contents;
872928
base::FilePath test_dir = test_data_dir_.Append(FILE_PATH_LITERAL("platform_apps")).Append(FILE_PATH_LITERAL("local_pdf"));

0 commit comments

Comments
 (0)