// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/process/launch.h"
#include "base/strings/string_util.h"
#include "testing/gtest/include/gtest/gtest.h"

base::FilePath GinShellPath() {
  base::FilePath dir;
  PathService::Get(base::DIR_EXE, &dir);
  return dir.AppendASCII("gin_shell");
}

base::FilePath HelloWorldPath() {
  base::FilePath path;
  PathService::Get(base::DIR_SOURCE_ROOT, &path);
  return path
    .AppendASCII("gin")
    .AppendASCII("shell")
    .AppendASCII("hello_world.js");
}

TEST(GinShellTest, HelloWorld) {
  base::FilePath gin_shell_path(GinShellPath());
  base::FilePath hello_world_path(HelloWorldPath());
  ASSERT_TRUE(base::PathExists(gin_shell_path));
  ASSERT_TRUE(base::PathExists(hello_world_path));

  CommandLine cmd(gin_shell_path);
  cmd.AppendArgPath(hello_world_path);
  std::string output;
  ASSERT_TRUE(base::GetAppOutput(cmd, &output));
  base::TrimWhitespaceASCII(output, base::TRIM_ALL, &output);
  ASSERT_EQ("Hello World", output);
}

// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/process/launch.h"
#include "base/strings/string_util.h"
#include "testing/gtest/include/gtest/gtest.h"

base::FilePath GinShellPath() {
  base::FilePath dir;
  PathService::Get(base::DIR_EXE, &dir);
  return dir.AppendASCII("gin_shell");
}

base::FilePath HelloWorldPath() {
  base::FilePath path;
  PathService::Get(base::DIR_SOURCE_ROOT, &path);
  return path
    .AppendASCII("gin")
    .AppendASCII("shell")
    .AppendASCII("hello_world.js");
}

TEST(GinShellTest, HelloWorld) {
  CommandLine cmd(GinShellPath());
  cmd.AppendArgPath(HelloWorldPath());
  std::string output;
  ASSERT_TRUE(base::GetAppOutput(cmd, &output));
  base::TrimWhitespaceASCII(output, base::TRIM_ALL, &output);
  ASSERT_EQ("Hello World", output);
}

--- 
+++ 
@@ -3,7 +3,7 @@
 // found in the LICENSE file.
 
 #include "base/command_line.h"
-#include "base/files/file_path.h"
+#include "base/file_util.h"
 #include "base/path_service.h"
 #include "base/process/launch.h"
 #include "base/strings/string_util.h"
@@ -25,8 +25,13 @@
 }
 
 TEST(GinShellTest, HelloWorld) {
-  CommandLine cmd(GinShellPath());
-  cmd.AppendArgPath(HelloWorldPath());
+  base::FilePath gin_shell_path(GinShellPath());
+  base::FilePath hello_world_path(HelloWorldPath());
+  ASSERT_TRUE(base::PathExists(gin_shell_path));
+  ASSERT_TRUE(base::PathExists(hello_world_path));
+
+  CommandLine cmd(gin_shell_path);
+  cmd.AppendArgPath(hello_world_path);
   std::string output;
   ASSERT_TRUE(base::GetAppOutput(cmd, &output));
   base::TrimWhitespaceASCII(output, base::TRIM_ALL, &output);
Verify that gin_shell and hello_world.js exist.

This issue: https://code.google.com/p/chromium/issues/detail?id=398549,
was difficult to debug because gin/shell/gin_shell_unittest.cc didn't verify
that its input files existed before forging ahead.

The unit test now verifies that the gin_shell and hello_world.js paths
exist before launching the former and loading the latter.


BUG=398549

Review URL: https://codereview.chromium.org/471623002

Cr-Commit-Position: 972c6d2dc6dd5efdad1377c0d224e03eb8f276f7@{#289599}
git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@289599 0039d316-1c4b-4281-b951-d872f2087c98
