Ejemplo n.º 1
0
        public void FindAndAttachToNaClPluginTest()
        {
            MockProcessSearcher processResults = new MockProcessSearcher();

            using (PluginDebuggerGDB target = new PluginDebuggerGDB(dte_, properties_))
            {
                PluginDebuggerBase_Accessor targetBase = new PluginDebuggerBase_Accessor(
                    new PrivateObject(target, new PrivateType(typeof(PluginDebuggerBase))));
                targetBase.debuggedChromeMainProcess_ = System.Diagnostics.Process.GetCurrentProcess();

                uint currentProcId = (uint)targetBase.debuggedChromeMainProcess_.Id;

                // Target nacl process flag.
                string naclCommandLine = Strings.NaClLoaderFlag;

                // Fake the list of processes on the system.
                processResults.ProcessList.Add(
                    new ProcessInfo(
                        currentProcId,
                        currentProcId,
                        string.Empty,
                        Strings.NaClDebugFlag,
                        Strings.ChromeProcessName));
                processResults.ProcessList.Add(
                    new ProcessInfo(1, currentProcId, string.Empty, string.Empty, "MyParentProcess"));
                processResults.ProcessList.Add(
                    new ProcessInfo(11, 1, string.Empty, naclCommandLine, Strings.NaClProcessName));

                // This is missing some relevant command line args, should not be attached to.
                processResults.ProcessList.Add(
                    new ProcessInfo(13, 1, string.Empty, string.Empty, Strings.NaClProcessName));

                // This doesn't have chrome process as their parent, so they should not be attached to.
                processResults.ProcessList.Add(
                    new ProcessInfo(15, 15, string.Empty, naclCommandLine, Strings.NaClProcessName));

                // Set the private value to the mock object (can't use accessor since no valid cast).
                FieldInfo processSearcherField = typeof(PluginDebuggerBase).GetField(
                    "processSearcher_",
                    BindingFlags.NonPublic | BindingFlags.Instance);
                processSearcherField.SetValue(targetBase.Target, processResults);

                // Test that the correct processes are attached to.
                bool goodNaCl = false;
                var  handler  = new EventHandler <NativeClientVSAddIn.PluginDebuggerBase.PluginFoundEventArgs>(
                    delegate(object unused, NativeClientVSAddIn.PluginDebuggerBase.PluginFoundEventArgs args)
                {
                    switch (args.ProcessID)
                    {
                    case 11:
                        if (goodNaCl)
                        {
                            Assert.Fail("Should not attach twice to same nacl process");
                        }

                        goodNaCl = true;
                        break;

                    case 13:
                        Assert.Fail("Should not attach to nacl process with bad args");
                        break;

                    case 15:
                        Assert.Fail("Should not attach to nacl process that is not "
                                    + "descendant of Visual Studio");
                        break;

                    default:
                        Assert.Fail("Should not attach to non-pepper/non-nacl process");
                        break;
                    }
                });

                target.PluginFoundEvent += handler;
                target.FindAndAttachToPlugin(null, null);
                target.PluginFoundEvent -= handler;

                Assert.IsTrue(goodNaCl, "Failed to attach to NaCl process");
            }
        }
Ejemplo n.º 2
0
        public void FindAndAttachToPepperPluginTest()
        {
            MockProcessSearcher processResults = new MockProcessSearcher();

            using (PluginDebuggerVS target = new PluginDebuggerVS(dte_, properties_))
            {
                PluginDebuggerBase_Accessor targetBase = new PluginDebuggerBase_Accessor(
                    new PrivateObject(target, new PrivateType(typeof(PluginDebuggerBase))));
                targetBase.debuggedChromeMainProcess_ = System.Diagnostics.Process.GetCurrentProcess();
                uint currentProcId = (uint)targetBase.debuggedChromeMainProcess_.Id;

                string pluginLoadFlag = string.Format(
                    Strings.PepperProcessPluginFlagFormat, properties_.PluginAssembly);
                string pepperCommandLine = string.Concat(
                    pluginLoadFlag, " ", Strings.ChromeRendererFlag);

                // Fake the list of processes on the system.
                processResults.ProcessList.Add(
                    new ProcessInfo(
                        currentProcId,
                        currentProcId,
                        string.Empty,
                        Strings.NaClDebugFlag,
                        Strings.ChromeProcessName));
                processResults.ProcessList.Add(
                    new ProcessInfo(1, currentProcId, string.Empty, string.Empty, "MyParentProcess"));
                processResults.ProcessList.Add(
                    new ProcessInfo(10, 1, string.Empty, pepperCommandLine, Strings.ChromeProcessName));

                // This is missing some relevant command line args, and should not be attached to.
                processResults.ProcessList.Add(
                    new ProcessInfo(12, 1, string.Empty, pluginLoadFlag, Strings.ChromeProcessName));

                // This doesn't have this process as its parent, and should not be attached to.
                processResults.ProcessList.Add(
                    new ProcessInfo(14, 14, string.Empty, pepperCommandLine, Strings.ChromeProcessName));

                // Set the private value to the mock object (can't use accessor since no valid cast).
                FieldInfo processSearcherField = typeof(PluginDebuggerBase).GetField(
                    "processSearcher_",
                    BindingFlags.NonPublic | BindingFlags.Instance);
                processSearcherField.SetValue(targetBase.Target, processResults);

                // Test that the correct processes are attached to.
                bool goodPepper = false;
                var  handler    = new EventHandler <NativeClientVSAddIn.PluginDebuggerBase.PluginFoundEventArgs>(
                    delegate(object unused, NativeClientVSAddIn.PluginDebuggerBase.PluginFoundEventArgs args)
                {
                    switch (args.ProcessID)
                    {
                    case 10:
                        if (goodPepper)
                        {
                            Assert.Fail("Should not attach twice to same pepper process");
                        }

                        goodPepper = true;
                        break;

                    case 12:
                        Assert.Fail("Should not attach to pepper process with bad args");
                        break;

                    case 14:
                        Assert.Fail("Should not attach to pepper process that is not "
                                    + "descendant of Visual Studio");
                        break;

                    default:
                        Assert.Fail("Should not attach to non-pepper/non-nacl process");
                        break;
                    }
                });

                target.PluginFoundEvent += handler;
                target.FindAndAttachToPlugin(null, null);
                target.PluginFoundEvent -= handler;

                Assert.IsTrue(goodPepper, "Failed to attach to pepper process");
            }
        }
    public void FindAndAttachToNaClPluginTest()
    {
      MockProcessSearcher processResults = new MockProcessSearcher();

      using (PluginDebuggerGDB target = new PluginDebuggerGDB(dte_, properties_))
      {
        PluginDebuggerBase_Accessor targetBase = new PluginDebuggerBase_Accessor(
            new PrivateObject(target, new PrivateType(typeof(PluginDebuggerBase))));
        targetBase.debuggedChromeMainProcess_ = System.Diagnostics.Process.GetCurrentProcess();

        uint currentProcId = (uint)targetBase.debuggedChromeMainProcess_.Id;

        // Target nacl process flag.
        string naclCommandLine = Strings.NaClLoaderFlag;

        // Fake the list of processes on the system.
        processResults.ProcessList.Add(
            new ProcessInfo(
                currentProcId,
                currentProcId,
                string.Empty,
                Strings.NaClDebugFlag,
                Strings.ChromeProcessName));
        processResults.ProcessList.Add(
            new ProcessInfo(1, currentProcId, string.Empty, string.Empty, "MyParentProcess"));
        processResults.ProcessList.Add(
            new ProcessInfo(11, 1, string.Empty, naclCommandLine, Strings.NaClProcessName));

        // This is missing some relevant command line args, should not be attached to.
        processResults.ProcessList.Add(
            new ProcessInfo(13, 1, string.Empty, string.Empty, Strings.NaClProcessName));

        // This doesn't have chrome process as their parent, so they should not be attached to.
        processResults.ProcessList.Add(
            new ProcessInfo(15, 15, string.Empty, naclCommandLine, Strings.NaClProcessName));

        // Set the private value to the mock object (can't use accessor since no valid cast).
        FieldInfo processSearcherField = typeof(PluginDebuggerBase).GetField(
            "processSearcher_",
            BindingFlags.NonPublic | BindingFlags.Instance);
        processSearcherField.SetValue(targetBase.Target, processResults);

        // Test that the correct processes are attached to.
        bool goodNaCl = false;
        var handler = new EventHandler<NativeClientVSAddIn.PluginDebuggerBase.PluginFoundEventArgs>(
          delegate(object unused, NativeClientVSAddIn.PluginDebuggerBase.PluginFoundEventArgs args)
          {
            switch (args.ProcessID)
            {
              case 11:
                if (goodNaCl)
                {
                  Assert.Fail("Should not attach twice to same nacl process");
                }

                goodNaCl = true;
                break;
              case 13:
                Assert.Fail("Should not attach to nacl process with bad args");
                break;
              case 15:
                Assert.Fail("Should not attach to nacl process that is not "
                          + "descendant of Visual Studio");
                break;
              default:
                Assert.Fail("Should not attach to non-pepper/non-nacl process");
                break;
            }
          });

        target.PluginFoundEvent += handler;
        target.FindAndAttachToPlugin(null, null);
        target.PluginFoundEvent -= handler;

        Assert.IsTrue(goodNaCl, "Failed to attach to NaCl process");
      }
    }
    public void FindAndAttachToPepperPluginTest()
    {
      MockProcessSearcher processResults = new MockProcessSearcher();

      using (PluginDebuggerVS target = new PluginDebuggerVS(dte_, properties_))
      {
        PluginDebuggerBase_Accessor targetBase = new PluginDebuggerBase_Accessor(
            new PrivateObject(target, new PrivateType(typeof(PluginDebuggerBase))));
        targetBase.debuggedChromeMainProcess_ = System.Diagnostics.Process.GetCurrentProcess();
        uint currentProcId = (uint)targetBase.debuggedChromeMainProcess_.Id;

        string pluginLoadFlag = string.Format(
            Strings.PepperProcessPluginFlagFormat, properties_.PluginAssembly);
        string pepperCommandLine = string.Concat(
            pluginLoadFlag, " ", Strings.ChromeRendererFlag);

        // Fake the list of processes on the system.
        processResults.ProcessList.Add(
            new ProcessInfo(
                currentProcId,
                currentProcId,
                string.Empty,
                Strings.NaClDebugFlag,
                Strings.ChromeProcessName));
        processResults.ProcessList.Add(
            new ProcessInfo(1, currentProcId, string.Empty, string.Empty, "MyParentProcess"));
        processResults.ProcessList.Add(
            new ProcessInfo(10, 1, string.Empty, pepperCommandLine, Strings.ChromeProcessName));

        // This is missing some relevant command line args, and should not be attached to.
        processResults.ProcessList.Add(
            new ProcessInfo(12, 1, string.Empty, pluginLoadFlag, Strings.ChromeProcessName));

        // This doesn't have this process as its parent, and should not be attached to.
        processResults.ProcessList.Add(
            new ProcessInfo(14, 14, string.Empty, pepperCommandLine, Strings.ChromeProcessName));

        // Set the private value to the mock object (can't use accessor since no valid cast).
        FieldInfo processSearcherField = typeof(PluginDebuggerBase).GetField(
            "processSearcher_",
            BindingFlags.NonPublic | BindingFlags.Instance);
        processSearcherField.SetValue(targetBase.Target, processResults);

        // Test that the correct processes are attached to.
        bool goodPepper = false;
        var handler = new EventHandler<NativeClientVSAddIn.PluginDebuggerBase.PluginFoundEventArgs>(
          delegate(object unused, NativeClientVSAddIn.PluginDebuggerBase.PluginFoundEventArgs args)
          {
            switch (args.ProcessID)
            {
              case 10:
                if (goodPepper)
                {
                  Assert.Fail("Should not attach twice to same pepper process");
                }

                goodPepper = true;
                break;
              case 12:
                Assert.Fail("Should not attach to pepper process with bad args");
                break;
              case 14:
                Assert.Fail("Should not attach to pepper process that is not "
                          + "descendant of Visual Studio");
                break;
              default:
                Assert.Fail("Should not attach to non-pepper/non-nacl process");
                break;
            }
          });

        target.PluginFoundEvent += handler;
        target.FindAndAttachToPlugin(null, null);
        target.PluginFoundEvent -= handler;

        Assert.IsTrue(goodPepper, "Failed to attach to pepper process");
      }
    }