Remove hardcoded tests URLs from apptests.

Hardcoded URLs cause problems if the test is given a different name. This occurs when
compiling the test with the NaCl toolchain.

BUG=401761
R=jamesr@chromium.org

Review URL: https://codereview.chromium.org/996533002
diff --git a/mojo/public/cpp/application/lib/application_test_base.cc b/mojo/public/cpp/application/lib/application_test_base.cc
index 406c826..af6e13a 100644
--- a/mojo/public/cpp/application/lib/application_test_base.cc
+++ b/mojo/public/cpp/application/lib/application_test_base.cc
@@ -17,6 +17,9 @@
 // Share the application command-line arguments with multiple application tests.
 Array<String> g_args;
 
+// Share the application URL with multiple application tests.
+String g_url;
+
 // Application request handle passed from the shell in MojoMain, stored in
 // between SetUp()/TearDown() so we can (re-)intialize new ApplicationImpls.
 InterfaceRequest<Application> g_application_request;
@@ -51,6 +54,7 @@
                   Array<String> args,
                   const mojo::String& url) override {
     *args_ = args.Pass();
+    g_url = url;
     g_application_request = binding_.Unbind();
     g_shell = shell.Pass();
   }
@@ -140,7 +144,7 @@
                                           g_application_request.Pass());
 
   // Fake application initialization with the given command line arguments.
-  application_impl_->Initialize(g_shell.Pass(), g_args.Clone(), "");
+  application_impl_->Initialize(g_shell.Pass(), g_args.Clone(), g_url);
 }
 
 void ApplicationTestBase::TearDown() {
diff --git a/services/view_manager/view_manager_client_apptest.cc b/services/view_manager/view_manager_client_apptest.cc
index 82e2550..fe2964f 100644
--- a/services/view_manager/view_manager_client_apptest.cc
+++ b/services/view_manager/view_manager_client_apptest.cc
@@ -27,9 +27,6 @@
 
 namespace {
 
-const char kViewManagerClientTestAppURL[] =
-    "mojo:mojo_view_manager_client_apptests";
-
 base::RunLoop* current_run_loop = nullptr;
 
 void TimeoutRunLoop(const base::Closure& timeout_task, bool* timeout) {
@@ -206,7 +203,7 @@
   ViewManager* Embed(ViewManager* view_manager, View* view) {
     DCHECK_EQ(view_manager, view->view_manager());
     most_recent_view_manager_ = nullptr;
-    view->Embed(kViewManagerClientTestAppURL);
+    view->Embed(application_impl()->url());
     if (!DoRunLoopWithTimeout())
       return nullptr;
     ViewManager* vm = nullptr;
@@ -231,7 +228,7 @@
     ApplicationTestBase::SetUp();
 
     view_manager_context_.reset(new ViewManagerContext(application_impl()));
-    view_manager_context_->Embed(kViewManagerClientTestAppURL);
+    view_manager_context_->Embed(application_impl()->url());
     ASSERT_TRUE(DoRunLoopWithTimeout());
     std::swap(window_manager_, most_recent_view_manager_);
   }
@@ -387,7 +384,7 @@
   window_manager()->GetRoot()->AddChild(view);
   ViewManager* embedded = Embed(window_manager(), view);
   ASSERT_NE(nullptr, embedded);
-  EXPECT_EQ(kViewManagerClientTestAppURL, embedded->GetEmbedderURL());
+  EXPECT_EQ(application_impl()->url(), embedded->GetEmbedderURL());
 }
 
 // TODO(alhaad): Currently, the RunLoop gets stuck waiting for order change.
diff --git a/services/view_manager/view_manager_service_apptest.cc b/services/view_manager/view_manager_service_apptest.cc
index 0d5eddf..01bdd0f 100644
--- a/services/view_manager/view_manager_service_apptest.cc
+++ b/services/view_manager/view_manager_service_apptest.cc
@@ -80,12 +80,12 @@
   return result == ERROR_CODE_NONE;
 }
 
-bool EmbedUrl(ViewManagerService* vm, Id root_id) {
+bool EmbedUrl(ViewManagerService* vm, const String& url, Id root_id) {
   bool result = false;
   base::RunLoop run_loop;
   {
-    vm->EmbedUrl("mojo:view_manager_service_apptests", root_id, nullptr,
-                 nullptr, base::Bind(&BoolResultCallback, &run_loop, &result));
+    vm->EmbedUrl(url, root_id, nullptr, nullptr,
+                 base::Bind(&BoolResultCallback, &run_loop, &result));
   }
   run_loop.Run();
   return result;
@@ -442,7 +442,7 @@
   scoped_ptr<ViewManagerClientImpl> EstablishConnectionViaEmbed(
       ViewManagerService* owner,
       Id root_id) {
-    if (!EmbedUrl(owner, root_id)) {
+    if (!EmbedUrl(owner, application_impl()->url(), root_id)) {
       ADD_FAILURE() << "Embed() failed";
       return nullptr;
     }
@@ -455,8 +455,7 @@
     client->WaitForOnEmbed();
 
     const std::string expected_creator =
-        owner == vm1() ? "mojo:window_manager"
-                       : "mojo:view_manager_service_apptests";
+        owner == vm1() ? "mojo:window_manager" : application_impl()->url();
     EXPECT_EQ("OnEmbed creator=" + expected_creator,
               SingleChangeToDescription(*client->tracker()->changes()));
     return client.Pass();
diff --git a/services/window_manager/window_manager_apptest.cc b/services/window_manager/window_manager_apptest.cc
index f412410..818999f 100644
--- a/services/window_manager/window_manager_apptest.cc
+++ b/services/window_manager/window_manager_apptest.cc
@@ -108,7 +108,7 @@
 
 TEST_F(WindowManagerApplicationTest, Embed) {
   EXPECT_EQ(nullptr, test_application_.root());
-  EmbedApplicationWithURL("mojo:window_manager_apptests");
+  EmbedApplicationWithURL(application_impl()->url());
   EXPECT_NE(nullptr, test_application_.root());
 }
 
@@ -126,7 +126,7 @@
 };
 
 TEST_F(WindowManagerApplicationTest, SetCaptureFailsFromNonVM) {
-  EmbedApplicationWithURL("mojo:window_manager_apptests");
+  EmbedApplicationWithURL(application_impl()->url());
   bool callback_value = true;
   base::RunLoop run_loop;
   window_manager_->SetCapture(test_application_.root()->id(),
@@ -137,7 +137,7 @@
 }
 
 TEST_F(WindowManagerApplicationTest, FocusWindowFailsFromNonVM) {
-  EmbedApplicationWithURL("mojo:window_manager_apptests");
+  EmbedApplicationWithURL(application_impl()->url());
   bool callback_value = true;
   base::RunLoop run_loop;
   window_manager_->FocusWindow(test_application_.root()->id(),
@@ -148,7 +148,7 @@
 }
 
 TEST_F(WindowManagerApplicationTest, ActivateWindowFailsFromNonVM) {
-  EmbedApplicationWithURL("mojo:window_manager_apptests");
+  EmbedApplicationWithURL(application_impl()->url());
   bool callback_value = true;
   base::RunLoop run_loop;
   window_manager_->ActivateWindow(test_application_.root()->id(),
@@ -183,7 +183,7 @@
 };
 
 TEST_F(WindowManagerApplicationTest, GetFocusedAndActiveViewsFailsWithoutFC) {
-  EmbedApplicationWithURL("mojo:window_manager_apptests");
+  EmbedApplicationWithURL(application_impl()->url());
   uint32 capture_view_id = -1;
   uint32 focused_view_id = -1;
   uint32 active_view_id = -1;