More system app jank tests
Simple usecases for Books, Camera, Chrome, Gmail and Maps

Change-Id: Iccf6f5a4c9271753ebd489471a6774b392f1da49
diff --git a/jank/sysapp/src/com/android/sysapp/janktests/BooksJankTests.java b/jank/sysapp/src/com/android/sysapp/janktests/BooksJankTests.java
new file mode 100644
index 0000000..e8a94ee
--- /dev/null
+++ b/jank/sysapp/src/com/android/sysapp/janktests/BooksJankTests.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sysapp.janktests;
+
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.support.test.jank.GfxMonitor;
+import android.support.test.jank.JankTest;
+import android.support.test.jank.JankTestBase;
+import android.support.test.launcherhelper.ILauncherStrategy;
+import android.support.test.launcherhelper.LauncherStrategyFactory;
+import android.support.test.uiautomator.By;
+import android.support.test.uiautomator.Direction;
+import android.support.test.uiautomator.UiDevice;
+import android.support.test.uiautomator.UiObject2;
+import android.support.test.uiautomator.UiObjectNotFoundException;
+import android.support.test.uiautomator.Until;
+import android.widget.Button;
+import android.widget.ProgressBar;
+
+import junit.framework.Assert;
+
+/**
+ * Jank test for Books app recommendation page fling
+ */
+
+public class BooksJankTests extends JankTestBase {
+    private static final int LONG_TIMEOUT = 1000;
+    private static final int SHORT_TIMEOUT = 1000;
+    private static final int INNER_LOOP = 5;
+    private static final int EXPECTED_FRAMES = 100;
+    private static final String PACKAGE_NAME = "com.google.android.apps.books";
+    private static final String APP_NAME = "Play Books";
+    private UiDevice mDevice;
+    private ILauncherStrategy mLauncherStrategy = null;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        mDevice = UiDevice.getInstance(getInstrumentation());
+        try {
+            mDevice.setOrientationNatural();
+        } catch (RemoteException e) {
+            throw new RuntimeException("failed to freeze device orientaion", e);
+        }
+        mLauncherStrategy = LauncherStrategyFactory.getInstance(mDevice).getLauncherStrategy();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        mDevice.unfreezeRotation();
+        super.tearDown();
+    }
+
+    public void launchBooks () throws UiObjectNotFoundException {
+        mLauncherStrategy.launch(APP_NAME, PACKAGE_NAME);
+        dismissClings();
+        openMyLibrary();
+        Assert.assertTrue("Books haven't loaded yet", getNumberOfVisibleBooks() > 3);
+    }
+
+    // Measures jank while fling books mylibrary
+    @JankTest(beforeTest="launchBooks", expectedFrames=EXPECTED_FRAMES)
+    @GfxMonitor(processName=PACKAGE_NAME)
+    public void testBooksRecommendationPageFling() {
+        UiObject2 container = mDevice.wait(Until.findObject(
+                By.res(PACKAGE_NAME, "content_container")), LONG_TIMEOUT);
+        for (int i = 0; i < INNER_LOOP; i++) {
+          container.scroll(Direction.DOWN, 1.0f);
+          SystemClock.sleep(SHORT_TIMEOUT);
+          container.scroll(Direction.UP, 1.0f);
+        }
+    }
+
+    // All helper methods are at bottom
+    // with the assumptions is that these will have their own library
+    private void dismissClings() {
+        // Dismiss confidentiality warning. It's okay to timeout here.
+        UiObject2 warning = mDevice.wait(
+                Until.findObject(By.clazz(".Button").text("OK")), LONG_TIMEOUT);
+        if (warning != null) {
+            warning. click();
+        }
+        // Close the drawer.
+        UiObject2 close = mDevice.wait(
+                Until.findObject(By.desc("Hide navigation drawer")), LONG_TIMEOUT);
+        if (close != null) {
+            close.click();
+        }
+        // Turn sync off
+        UiObject2 syncoff = mDevice.wait(Until.findObject(
+                By.clazz(Button.class).text("Keep sync off")), LONG_TIMEOUT);
+        if (syncoff != null) {
+            syncoff.click();
+        }
+    }
+
+    public void openNavigationDrawer() {
+      if (!mDevice.hasObject(By.res(PACKAGE_NAME, "play_drawer_container"))) {
+          mDevice.findObject(By.desc("Show navigation drawer")).click();
+          Assert.assertTrue("Failed to open navigation drawer", mDevice.wait(
+              Until.hasObject(By.res(PACKAGE_NAME, "play_drawer_list")), LONG_TIMEOUT));
+
+          // Extra sleep to wait for the drawer to finish sliding in
+          SystemClock.sleep(500);
+      }
+  }
+
+    public void openMyLibrary() {
+        openNavigationDrawer();
+        UiObject2 library = mDevice.wait(
+            Until.findObject(By.text("My Library")), LONG_TIMEOUT);
+        Assert.assertNotNull("Could not find 'My Library' button", library);
+        library.click();
+    }
+
+    public int getNumberOfVisibleBooks() {
+      UiObject2 list = mDevice.wait(
+              Until.findObject(By.res(PACKAGE_NAME, "cards_grid")), LONG_TIMEOUT);
+      Assert.assertNotNull("Failed to locate 'cards_grid'", list);
+      return list.getChildCount();
+    }
+}
diff --git a/jank/sysapp/src/com/android/sysapp/janktests/CameraJankTests.java b/jank/sysapp/src/com/android/sysapp/janktests/CameraJankTests.java
new file mode 100644
index 0000000..a1514cc
--- /dev/null
+++ b/jank/sysapp/src/com/android/sysapp/janktests/CameraJankTests.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sysapp.janktests;
+
+import android.os.RemoteException;
+import android.support.test.jank.GfxMonitor;
+import android.support.test.jank.JankTest;
+import android.support.test.jank.JankTestBase;
+import android.support.test.launcherhelper.ILauncherStrategy;
+import android.support.test.launcherhelper.LauncherStrategyFactory;
+import android.support.test.uiautomator.By;
+import android.support.test.uiautomator.BySelector;
+import android.support.test.uiautomator.UiDevice;
+import android.support.test.uiautomator.UiObject2;
+import android.support.test.uiautomator.UiObjectNotFoundException;
+import android.support.test.uiautomator.Until;
+import android.widget.Button;
+
+import junit.framework.Assert;
+
+/**
+ * Jank test for flipping front and back camera n times.
+ */
+
+public class CameraJankTests extends JankTestBase {
+    private static final int TIMEOUT = 3000;
+    private static final int INNER_LOOP = 5;
+    private static final int EXPECTED_FRAMES = 100;
+    private static final String PACKAGE_NAME = "com.google.android.GoogleCamera";
+    private static final String FRAMEWORK_PACKAGE_NAME = "com.android.camera2";
+    private static final String APP_NAME = "Camera";
+    private UiDevice mDevice;
+    private ILauncherStrategy mLauncherStrategy = null;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        mDevice = UiDevice.getInstance(getInstrumentation());
+        try {
+            mDevice.setOrientationNatural();
+        } catch (RemoteException e) {
+            throw new RuntimeException("failed to freeze device orientaion", e);
+        }
+        mLauncherStrategy = LauncherStrategyFactory.getInstance(mDevice).getLauncherStrategy();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        mDevice.unfreezeRotation();
+        super.tearDown();
+    }
+
+    public void launchCamera () throws UiObjectNotFoundException {
+        mLauncherStrategy.launch(APP_NAME, PACKAGE_NAME);
+        dismissClings();
+        BySelector threeDotsSelector = By.res(
+            FRAMEWORK_PACKAGE_NAME, "mode_options_toggle").desc("Options");
+        UiObject2 threeDots = mDevice.wait(Until.findObject(threeDotsSelector), TIMEOUT);
+        Assert.assertNotNull("Three dot icon is missing", threeDots);
+        threeDots.click();
+        // wait for next window to show up
+        mDevice.wait(Until.gone(threeDotsSelector), TIMEOUT);
+    }
+
+    // Measures jank while fling YouTube recommendation
+    @JankTest(beforeTest="launchCamera", expectedFrames=EXPECTED_FRAMES)
+    @GfxMonitor(processName=PACKAGE_NAME)
+    public void testFrontBackCameraFlip() {
+        UiObject2 cameraToggle = null;
+        BySelector cameraToggleSelector = By.res(FRAMEWORK_PACKAGE_NAME, "camera_toggle_button");
+        for (int i = 0; i < INNER_LOOP; i++) {
+          cameraToggle = mDevice.wait(Until.findObject(cameraToggleSelector), 3 * TIMEOUT);
+          Assert.assertNotNull("Camera flipper icon is missing", cameraToggle);
+          cameraToggle.click();
+          mDevice.wait(Until.gone(cameraToggleSelector), TIMEOUT);
+        }
+    }
+
+    private void dismissClings() {
+        // Dismiss tag next screen. It's okay to timeout. These dialog screens might not exist..
+        UiObject2 next = mDevice.wait(Until.findObject(
+                By.clazz(Button.class).text("NEXT")), 2 * TIMEOUT);
+        if (next != null) {
+            next.click();
+        }
+        // Choose sensor size. It's okay to timeout. These dialog screens might not exist..
+        UiObject2 sensor = mDevice.wait(Until.findObject(
+                By.res(PACKAGE_NAME, "confirm_button").text("OK, GOT IT")), 2 * TIMEOUT);
+        if (sensor != null) {
+            sensor.click();
+        }
+        // Dismiss the photo location dialog box if exist.
+        UiObject2 thanks = mDevice.wait(Until.findObject(
+                By.text("No thanks")), 2 * TIMEOUT);
+        if (thanks != null) {
+            thanks.click();
+        }
+        // Dismiss dogfood dialog
+        if (mDevice.wait(Until.hasObject(
+                By.res(PACKAGE_NAME, "internal_release_dialog_title")), 2 * TIMEOUT)) {
+            mDevice.findObject(By.res(FRAMEWORK_PACKAGE_NAME, "ok_button")).click();
+        }
+    }
+}
diff --git a/jank/sysapp/src/com/android/sysapp/janktests/ChromeJankTests.java b/jank/sysapp/src/com/android/sysapp/janktests/ChromeJankTests.java
new file mode 100644
index 0000000..7ef6407
--- /dev/null
+++ b/jank/sysapp/src/com/android/sysapp/janktests/ChromeJankTests.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sysapp.janktests;
+
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.support.test.jank.GfxMonitor;
+import android.support.test.jank.JankTest;
+import android.support.test.jank.JankTestBase;
+import android.support.test.launcherhelper.ILauncherStrategy;
+import android.support.test.launcherhelper.LauncherStrategyFactory;
+import android.support.test.uiautomator.By;
+import android.support.test.uiautomator.BySelector;
+import android.support.test.uiautomator.Direction;
+import android.support.test.uiautomator.UiDevice;
+import android.support.test.uiautomator.UiObject2;
+import android.support.test.uiautomator.UiObjectNotFoundException;
+import android.support.test.uiautomator.Until;
+import junit.framework.Assert;
+
+/**
+ * Jank test for Chorme apps
+ * Open overflow menu
+ */
+
+public class ChromeJankTests extends JankTestBase {
+    private static final int SHORT_TIMEOUT = 1000;
+    private static final int LONG_TIMEOUT = 30000;
+    private static final int INNER_LOOP = 5;
+    private static final int EXPECTED_FRAMES = 100;
+    private static final String PACKAGE_NAME = "com.android.chrome";
+    private static final String APP_NAME = "Chrome";
+    private UiDevice mDevice;
+    private ILauncherStrategy mLauncherStrategy = null;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        mDevice = UiDevice.getInstance(getInstrumentation());
+        try {
+            mDevice.setOrientationNatural();
+        } catch (RemoteException e) {
+            throw new RuntimeException("failed to freeze device orientaion", e);
+        }
+        mLauncherStrategy = LauncherStrategyFactory.getInstance(mDevice).getLauncherStrategy();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        mDevice.unfreezeRotation();
+        super.tearDown();
+    }
+
+    public void launchChrome () throws UiObjectNotFoundException {
+        mLauncherStrategy.launch(APP_NAME, PACKAGE_NAME);
+        mDevice.waitForIdle();
+        // To infer that test is ready to be executed
+        getOverflowMenu();
+    }
+
+    // Measures jank window render for overflow menu tap
+    @JankTest(beforeTest="launchChrome", expectedFrames=EXPECTED_FRAMES)
+    @GfxMonitor(processName=PACKAGE_NAME)
+    public void testChromeOverflowMenuTap() {
+        for (int i = 0; i < INNER_LOOP; i++) {
+            UiObject2 overflow = getOverflowMenu();
+            overflow.click();
+            SystemClock.sleep(100);
+            mDevice.pressBack();
+        }
+    }
+
+    public UiObject2 getOverflowMenu() {
+      UiObject2 overflow = mDevice.wait(
+          Until.findObject(By.desc("More options")), 5 * SHORT_TIMEOUT);
+      Assert.assertNotNull("Failed to locate overflow menu", overflow);
+      return overflow;
+    }
+}
diff --git a/jank/sysapp/src/com/android/sysapp/janktests/GMailJankTests.java b/jank/sysapp/src/com/android/sysapp/janktests/GMailJankTests.java
new file mode 100644
index 0000000..08cece5
--- /dev/null
+++ b/jank/sysapp/src/com/android/sysapp/janktests/GMailJankTests.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sysapp.janktests;
+
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.support.test.jank.GfxMonitor;
+import android.support.test.jank.JankTest;
+import android.support.test.jank.JankTestBase;
+import android.support.test.launcherhelper.ILauncherStrategy;
+import android.support.test.launcherhelper.LauncherStrategyFactory;
+import android.support.test.uiautomator.By;
+import android.support.test.uiautomator.BySelector;
+import android.support.test.uiautomator.Direction;
+import android.support.test.uiautomator.UiDevice;
+import android.support.test.uiautomator.UiObject2;
+import android.support.test.uiautomator.UiObjectNotFoundException;
+import android.support.test.uiautomator.Until;
+import junit.framework.Assert;
+
+/**
+ * Jank test for scrolling gmail inbox mails
+ */
+
+public class GMailJankTests extends JankTestBase {
+    private static final int SHORT_TIMEOUT = 1000;
+    private static final int LONG_TIMEOUT = 30000;
+    private static final int INNER_LOOP = 5;
+    private static final int EXPECTED_FRAMES = 100;
+    private static final String PACKAGE_NAME = "com.google.android.gm";
+    private static final String APP_NAME = "Gmail";
+    private UiDevice mDevice;
+    private ILauncherStrategy mLauncherStrategy = null;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        mDevice = UiDevice.getInstance(getInstrumentation());
+        try {
+            mDevice.setOrientationNatural();
+        } catch (RemoteException e) {
+            throw new RuntimeException("failed to freeze device orientaion", e);
+        }
+        mLauncherStrategy = LauncherStrategyFactory.getInstance(mDevice).getLauncherStrategy();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        mDevice.unfreezeRotation();
+        super.tearDown();
+    }
+
+    public void launchGMail () throws UiObjectNotFoundException {
+        mLauncherStrategy.launch(APP_NAME, PACKAGE_NAME);
+        dismissClings();
+        // Need any check for account-name??
+        waitForEmailSync();
+    }
+
+    // Measures jank while scrolling gmail inbox
+    @JankTest(beforeTest="launchGMail", expectedFrames=EXPECTED_FRAMES)
+    @GfxMonitor(processName=PACKAGE_NAME)
+    public void testGMailInboxFling() {
+        UiObject2 list = mDevice.wait(
+                Until.findObject(By.res(PACKAGE_NAME, "conversation_list_view")), 5000);
+        Assert.assertNotNull("Failed to locate 'conversation_list_view", list);
+        for (int i = 0; i < INNER_LOOP; i++) {
+          list.scroll(Direction.DOWN, 1.0f);
+          SystemClock.sleep(SHORT_TIMEOUT);
+          list.scroll(Direction.UP, 1.0f);
+        }
+    }
+
+    private void dismissClings() {
+        UiObject2 welcomeScreenGotIt = mDevice.wait(
+            Until.findObject(By.res(PACKAGE_NAME, "welcome_tour_got_it")), 2000);
+        if (welcomeScreenGotIt != null) {
+            welcomeScreenGotIt.clickAndWait(Until.newWindow(), SHORT_TIMEOUT);
+        }
+        UiObject2 welcomeScreenSkip = mDevice.wait(
+            Until.findObject(By.res(PACKAGE_NAME, "welcome_tour_skip")), 2000);
+        if (welcomeScreenSkip != null) {
+          welcomeScreenSkip.clickAndWait(Until.newWindow(), SHORT_TIMEOUT);
+        }
+        UiObject2 tutorialDone = mDevice.wait(
+                Until.findObject(By.res(PACKAGE_NAME, "action_done")), 2 * SHORT_TIMEOUT);
+        if (tutorialDone != null) {
+            tutorialDone.clickAndWait(Until.newWindow(), SHORT_TIMEOUT);
+        }
+        mDevice.wait(Until.findObject(By.text("CONFIDENTIAL")), 2 * SHORT_TIMEOUT);
+        UiObject2 splash = mDevice.findObject(By.text("Ok, got it"));
+        if (splash != null) {
+            splash.clickAndWait(Until.newWindow(), SHORT_TIMEOUT);
+        }
+    }
+
+    public void waitForEmailSync() {
+        // Wait up to 2 seconds for a "waiting" message to appear
+        mDevice.wait(Until.hasObject(By.text("Waiting for sync")), 2 * SHORT_TIMEOUT);
+        // Wait until any "waiting" messages are gone
+        Assert.assertTrue("'Waiting for sync' timed out",
+                mDevice.wait(Until.gone(By.text("Waiting for sync")), LONG_TIMEOUT));
+        Assert.assertTrue("'Loading' timed out",
+                mDevice.wait(Until.gone(By.text("Loading")), LONG_TIMEOUT));
+    }
+}
diff --git a/jank/sysapp/src/com/android/sysapp/janktests/MapsJankTests.java b/jank/sysapp/src/com/android/sysapp/janktests/MapsJankTests.java
new file mode 100644
index 0000000..d8de12a
--- /dev/null
+++ b/jank/sysapp/src/com/android/sysapp/janktests/MapsJankTests.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sysapp.janktests;
+
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.support.test.jank.GfxMonitor;
+import android.support.test.jank.JankTest;
+import android.support.test.jank.JankTestBase;
+import android.support.test.launcherhelper.ILauncherStrategy;
+import android.support.test.launcherhelper.LauncherStrategyFactory;
+import android.support.test.uiautomator.By;
+import android.support.test.uiautomator.BySelector;
+import android.support.test.uiautomator.Direction;
+import android.support.test.uiautomator.StaleObjectException;
+import android.support.test.uiautomator.UiDevice;
+import android.support.test.uiautomator.UiObject2;
+import android.support.test.uiautomator.UiObjectNotFoundException;
+import android.support.test.uiautomator.Until;
+import junit.framework.Assert;
+
+/**
+ * Jank test for Map
+ * click on search box to bring up ime window
+ * click on back to go back to map
+ */
+
+public class MapsJankTests extends JankTestBase {
+    private static final int SHORT_TIMEOUT = 1000;
+    private static final int LONG_TIMEOUT = 30000;
+    private static final int INNER_LOOP = 5;
+    private static final int EXPECTED_FRAMES = 100;
+    private static final String PACKAGE_NAME = "com.google.android.apps.maps";
+    public static final String RES_PACKAGE = "com.google.android.apps.gmm";
+    private static final String APP_NAME = "Maps";
+    private UiDevice mDevice;
+    private ILauncherStrategy mLauncherStrategy = null;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        mDevice = UiDevice.getInstance(getInstrumentation());
+        try {
+            mDevice.setOrientationNatural();
+        } catch (RemoteException e) {
+            throw new RuntimeException("failed to freeze device orientaion", e);
+        }
+        mLauncherStrategy = LauncherStrategyFactory.getInstance(mDevice).getLauncherStrategy();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        mDevice.unfreezeRotation();
+        super.tearDown();
+    }
+
+    public void launchMaps () throws UiObjectNotFoundException {
+        mLauncherStrategy.launch(APP_NAME, PACKAGE_NAME);
+        mDevice.waitForIdle();
+        dismissCling();
+        // To infer that test is ready to be executed
+        int counter = 5;
+        while (getSearchBox() == null && counter > 0){
+            SystemClock.sleep(1000);
+            --counter;
+        }
+        Assert.assertNotNull("Failed to find 'Search'", getSearchBox());
+    }
+
+    @JankTest(beforeTest="launchMaps", expectedFrames=EXPECTED_FRAMES)
+    @GfxMonitor(processName=PACKAGE_NAME)
+    public void testMapsOverflowMenuTap() {
+        for (int i = 0; i < INNER_LOOP; i++) {
+            try {
+                getSearchBox().click();
+            } catch (StaleObjectException se) {
+                getSearchBox().click();
+            }
+            SystemClock.sleep(100);
+            // to go away input kb
+            mDevice.pressBack();
+            // to go back to map search
+            mDevice.pressBack();
+        }
+    }
+
+    private UiObject2 getSearchBox(){
+        mDevice.wait(Until.findObject(By.desc("Search")), SHORT_TIMEOUT).click();
+        UiObject2 search = mDevice.wait(Until.findObject(
+            By.res(RES_PACKAGE, "search_omnibox_edit_text")), SHORT_TIMEOUT);
+        if (search == null ) {
+            search = mDevice.wait(Until.findObject(
+                    By.res(RES_PACKAGE, "search_omnibox_text_box")), SHORT_TIMEOUT);
+        }
+        Assert.assertNotNull("Search box is null", search);
+        return search;
+    }
+
+    private void dismissCling(){
+        // Accept terms
+        UiObject2 terms = mDevice.wait(Until.findObject(By.text("Accept & continue")), 5000);
+        if (terms != null) {
+            terms.click();
+        }
+        // Enable location services
+        UiObject2 location = mDevice.wait(Until.findObject(By.text("Yes, I'm in")), 5000);
+        if (location != null) {
+            location.click();
+        }
+        // Dismiss cling
+        UiObject2 cling = mDevice.wait(
+                Until.findObject(By.res(PACKAGE_NAME, "tapherehint_textbox")), 500);
+        if (cling != null) {
+            cling.click();
+        }
+        // Reset map view
+        UiObject2 resetView = mDevice.findObject(By.res(PACKAGE_NAME, "mylocation_button"));
+        if (resetView != null) {
+            resetView.click();
+            mDevice.waitForIdle(5000);
+        }
+        // dismiss yet another tutorial
+        UiObject2 tutorial = mDevice.findObject(By.res(PACKAGE_NAME, "tutorial_side_menu_got_it"));
+        if (tutorial != null) {
+            tutorial.click();
+        }
+    }
+}
diff --git a/jank/sysapp/src/com/android/sysapp/janktests/YouTubeJankTests.java b/jank/sysapp/src/com/android/sysapp/janktests/YouTubeJankTests.java
index 17f8da5..2cfbdae 100644
--- a/jank/sysapp/src/com/android/sysapp/janktests/YouTubeJankTests.java
+++ b/jank/sysapp/src/com/android/sysapp/janktests/YouTubeJankTests.java
@@ -17,6 +17,7 @@
 package com.android.sysapp.janktests;
 
 import android.os.RemoteException;
+import android.os.SystemClock;
 import android.support.test.jank.GfxMonitor;
 import android.support.test.jank.JankTest;
 import android.support.test.jank.JankTestBase;
@@ -36,7 +37,7 @@
 
 public class YouTubeJankTests extends JankTestBase {
     private static final int TIMEOUT = 5000;
-    private static final int INNER_LOOP = 3;
+    private static final int INNER_LOOP = 5;
     private static final int EXPECTED_FRAMES = 100;
     private static final String PACKAGE_NAME = "com.google.android.youtube";
     private static final String APP_NAME = "YouTube";
@@ -45,7 +46,8 @@
     private ILauncherStrategy mLauncherStrategy = null;
 
     @Override
-    public void setUp() {
+    public void setUp() throws Exception {
+        super.setUp();
         mDevice = UiDevice.getInstance(getInstrumentation());
         try {
             mDevice.setOrientationNatural();
@@ -63,12 +65,7 @@
 
     public void launchYouTube () throws UiObjectNotFoundException {
         mLauncherStrategy.launch(APP_NAME, PACKAGE_NAME);
-        // Dismiss the dogfood splash screen that might appear on first start
-        UiObject2 splash = mDevice.wait(
-                Until.findObject(By.res(PACKAGE_NAME, "dialog_message")), TIMEOUT);
-        if (splash != null) {
-            splash.click();
-        }
+        dismissCling();
     }
 
     // Measures jank while fling YouTube recommendation
@@ -80,9 +77,30 @@
         Assert.assertNotNull("Recommendation container is null", uiObject);
         for (int i = 0; i < INNER_LOOP; i++) {
             uiObject.scroll(Direction.DOWN, 1.0f);
-        }
-        for (int i = 0; i < INNER_LOOP; i++) {
+            SystemClock.sleep(100);
             uiObject.scroll(Direction.UP, 1.0f);
         }
     }
+
+    private void dismissCling() {
+        // Dismiss the dogfood splash screen that might appear on first start
+        UiObject2 dialog_dismiss_btn = mDevice.wait(Until.findObject(
+                By.res(PACKAGE_NAME, "dogfood_warning_dialog_dismiss_button").text("OK")), TIMEOUT);
+        if (dialog_dismiss_btn != null) {
+            dialog_dismiss_btn.click();
+        }
+        UiObject2 welcomeSkip = mDevice.wait(
+            Until.findObject(By.res(PACKAGE_NAME, "skip_button").text("Skip")), TIMEOUT);
+        if (welcomeSkip != null) {
+            welcomeSkip.click();
+        }
+        UiObject2 musicFaster = mDevice.wait(
+            Until.findObject(By.res(PACKAGE_NAME, "text").text("Find music faster")), TIMEOUT);
+        if (musicFaster != null) {
+            UiObject2 ok = mDevice.wait(
+                    Until.findObject(By.res(PACKAGE_NAME, "ok").text("OK")), TIMEOUT);
+            Assert.assertNotNull("No 'ok' button to bypass music", ok);
+            ok.click();
+      }
+    }
 }